win_edit 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. # open_scite.sh
  3. # Usage:
  4. # ./open_scite.sh /path/to/file [line_number] [column_number]
  5. set -euo pipefail
  6. if [[ $# -lt 1 || $# -gt 3 ]]; then
  7. echo "Usage: $0 <linux_path_to_file> [line_number] [column_number]"
  8. exit 1
  9. fi
  10. FILE_LINUX="$1"
  11. LINE="${2:-}"
  12. COL="${3:-}"
  13. if ! command -v wslpath >/dev/null 2>&1; then
  14. echo "Error: wslpath not found." >&2
  15. exit 1
  16. fi
  17. # Convert Linux path to Windows path
  18. FILE_WIN="$(wslpath -w "$FILE_LINUX")"
  19. # Build goto arg if line/col provided
  20. GOTO_ARG=""
  21. if [[ -n "$LINE" ]]; then
  22. if ! [[ "$LINE" =~ ^[0-9]+$ ]]; then
  23. echo "Error: line number must be numeric." >&2
  24. exit 1
  25. fi
  26. if [[ -n "$COL" && ! "$COL" =~ ^[0-9]+$ ]]; then
  27. echo "Error: column number must be numeric." >&2
  28. exit 1
  29. fi
  30. COL="${COL:-1}" # default col=1 if only line given
  31. GOTO_ARG="-goto:$LINE,$COL"
  32. fi
  33. # Debug info
  34. # echo "Opening in SciTE:"
  35. # echo " FILE_WIN=$FILE_WIN"
  36. # [[ -n "$GOTO_ARG" ]] && echo " GOTO_ARG=$GOTO_ARG"
  37. # Paths
  38. POWERSHELL="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
  39. SCITE="C:\\apps\\scite\\SciTE.exe"
  40. # Launch SciTE
  41. if [[ -n "$GOTO_ARG" ]]; then
  42. "$POWERSHELL" -NoProfile -Command \
  43. "Start-Process -FilePath '$SCITE' -ArgumentList \"$FILE_WIN\",\"$GOTO_ARG\""
  44. else
  45. "$POWERSHELL" -NoProfile -Command \
  46. "Start-Process -FilePath '$SCITE' -ArgumentList \"$FILE_WIN\""
  47. fi