-
-
Save nickodell/1834b190218c0fecb6733680f3407cb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Sublime Text Wrapper Script | |
| # Intended to launch Windows Sublime Text from WSL Sublime Merge | |
| # Usage: | |
| # Open sublime text | |
| # sublime_text_translate_path | |
| # Open specific file | |
| # sublime_text_translate_path myfile | |
| # Open specific file at specifc position | |
| # sublime_text_translate_path myfile:40 | |
| set -euo pipefail | |
| SUBL="/mnt/c/Program Files/Sublime Text/subl.exe" | |
| if [ "$#" -ne 1 ]; then | |
| # Execute unchanged | |
| exec "$SUBL" "$@" | |
| fi | |
| # Have one argument | |
| path="$1" | |
| # Is this argument with : in it? | |
| if [[ ! "$path" =~ ":" ]]; then | |
| # Translate to WSL | |
| path="$(wslpath -w "$path")" | |
| exec "$SUBL" "$path" | |
| fi | |
| # Split path:row:col, and translate path, and leave rest of argument unchanged | |
| first_path="$(cut -d: -f1 <<< "$path")" | |
| rest_of_path="$(cut -d: -f2- <<< "$path")" | |
| first_path="$(wslpath -w "$first_path")" | |
| exec "$SUBL" "$first_path:$rest_of_path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment