Last active
April 24, 2020 15:28
-
-
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
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
# 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