Created
April 28, 2019 19:23
-
-
Save evadne/82b60c3f7e9bae3f71a053fbdb1ca339 to your computer and use it in GitHub Desktop.
Properly invoke Sublime Text from WSL
This file contains 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
function subl () { | |
SublimePath="/mnt/c/Program Files/Sublime Text 3/subl.exe" | |
TargetPath=$(readlink -f $1) | |
HomePath="/home/evadne" | |
ProjectsPath=$(readlink -f $HomePath/projects) | |
SublimeProjectsPath=$(readlink -f $HomePath/sublime) | |
echo "Editing $TargetPath" | |
case $TargetPath/ in | |
$ProjectsPath/*) | |
ProjectNamespaceComponents=$(realpath --relative-to="$ProjectsPath" "$TargetPath") | |
if [[ "$ProjectNamespaceComponents" =~ '^([^/]+)/([^/]+)(.+)?$' ]] { | |
ProjectDirectory="$ProjectsPath/$match[1]/$match[2]" | |
SublimeProjectDirectory="$SublimeProjectsPath/projects/$match[1]" | |
mkdir -p $SublimeProjectDirectory | |
SublimeProjectName="$match[2].sublime-project" | |
SublimeProjectFolderPath=$(realpath --relative-to="$SublimeProjectDirectory" "$ProjectDirectory") | |
} | |
;; | |
$HomePath/*) | |
ProjectDirectory=$HomePath | |
SublimeProjectDirectory="$SublimeProjectsPath" | |
SublimeProjectName="home.sublime-project" | |
SublimeProjectFolderPath='\\\\wsl$\\Ubuntu\\home\\evadne' | |
;; | |
*/) | |
ProjectDirectory="/" | |
SublimeProjectDirectory="$SublimeProjectsPath" | |
SublimeProjectName="root.sublime-project" | |
SublimeProjectFolderPath='\\\\wsl$\\Ubuntu' | |
;; | |
esac | |
SublimeProjectPath="$SublimeProjectDirectory/$SublimeProjectName" | |
printf '{"folders": [{"path": "%s"}]}' "$SublimeProjectFolderPath" > "$SublimeProjectPath" | |
cat $SublimeProjectPath | |
pushd $SublimeProjectDirectory | |
$SublimePath --new-window --project $SublimeProjectName | |
popd | |
} |
This file contains 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
➜ ~ ls -al | grep mnt | |
lrwxrwxrwx 1 evadne evadne 15 Apr 26 14:36 projects -> /mnt/d/Projects | |
lrwxrwxrwx 1 evadne evadne 19 Apr 28 19:13 sublime -> /mnt/d/Sublime Text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment