Skip to content

Instantly share code, notes, and snippets.

@JacobDB
Last active April 24, 2020 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobDB/572f980e23ba11b5479e3df94a01a220 to your computer and use it in GitHub Desktop.
Save JacobDB/572f980e23ba11b5479e3df94a01a220 to your computer and use it in GitHub Desktop.
Small script to fix symlinked paths when opening VS Code from within WSL
# Modify VS Code CLI to expand symlinks before opening, to fix git status highlighting
code() {
# Set the path to VS Code
code_path="/mnt/c/Users/Jacob/AppData/Local/Programs/Microsoft VS Code/bin/code";
# Store converted arguments
converted=""
# Loop through all passed arguments
for arg in "$@"
do
# Retain line and colum number information
pattern="([^:]*)((:[0-9]+)+)?";
[[ $arg =~ $pattern ]]
prefix=${BASH_REMATCH[1]}
suffix=${BASH_REMATCH[2]}
if [[ -d $prefix ]] || [[ -f $prefix ]]
then
# Expand paths, resolving symlinks
converted="$converted $(readlink -f $prefix)$suffix"
else
# Retain non-path arguments
converted="$converted $arg"
fi
done
# Reconstruct the command
"$code_path" $converted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment