win_diff 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env bash
  2. # compare_wsl.sh
  3. # Usage: ./compare_wsl.sh /path/to/file1 /path/to/file2
  4. set -euo pipefail
  5. if [[ $# -ne 2 ]]; then
  6. echo "Usage: $0 <linux_path_to_file1> <linux_path_to_file2>"
  7. exit 1
  8. fi
  9. # Input (Linux) paths
  10. F1_LINUX="$1"
  11. F2_LINUX="$2"
  12. # Basic checks
  13. if [[ ! -e "$F1_LINUX" ]]; then
  14. echo "Error: '$F1_LINUX' does not exist." >&2
  15. exit 1
  16. fi
  17. if [[ ! -e "$F2_LINUX" ]]; then
  18. echo "Error: '$F2_LINUX' does not exist." >&2
  19. exit 1
  20. fi
  21. if ! command -v wslpath >/dev/null 2>&1; then
  22. echo "Error: wslpath not found." >&2
  23. exit 1
  24. fi
  25. # Resolve to absolute Linux paths (helps if you pass relative paths)
  26. # 'readlink -f' is available on most WSL distros; if not, remove these two lines.
  27. F1_LINUX="$(readlink -f "$F1_LINUX")"
  28. F2_LINUX="$(readlink -f "$F2_LINUX")"
  29. # === Prepare required variables ===
  30. # Filenames only
  31. F1_NAME="$(basename "$F1_LINUX")"
  32. F2_NAME="$(basename "$F2_LINUX")"
  33. # Windows-mapped absolute paths
  34. F1_PATH="$(wslpath -w "$F1_LINUX")"
  35. F2_PATH="$(wslpath -w "$F2_LINUX")"
  36. # (Optional) show what we computed
  37. #echo "F1_PATH=$F1_PATH"
  38. #echo "F1_NAME=$F1_NAME"
  39. #echo "F2_PATH=$F2_PATH"
  40. #echo "F2_NAME=$F2_NAME"
  41. # === Example: launch ExamDiff via Windows PowerShell ===
  42. # Adjust ExamDiff path if your version/path differs.
  43. POWERSHELL="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
  44. EXAMDIFF="C:\\Program Files\\ExamDiff Pro 16.0\\ExamDiff.exe"
  45. # Use Start-Process with an explicit -ArgumentList.
  46. # We wrap the entire PowerShell command in double quotes so Bash expands our vars,
  47. # and we escape the inner double quotes so PowerShell receives proper strings.
  48. "$POWERSHELL" -NoProfile -Command \
  49. "Start-Process -FilePath '$EXAMDIFF' -ArgumentList \
  50. \"$F1_PATH\",\"$F2_PATH\",\"/dn1:$F1_NAME\",\"/dn2:$F2_NAME\",\"/nh\""
  51. # If you prefer to block until ExamDiff exits, add: -Wait
  52. # ...like:
  53. # \"$F1_PATH\",\"$F2_PATH\",\"/dn1:$F1_NAME\",\"/dn2:$F2_NAME\",\"/nh\" -Wait