Skip to content

Instantly share code, notes, and snippets.

@WingTillDie
Last active July 30, 2023 07:04
Show Gist options
  • Save WingTillDie/3116a31c8240122b78601c75263ef694 to your computer and use it in GitHub Desktop.
Save WingTillDie/3116a31c8240122b78601c75263ef694 to your computer and use it in GitHub Desktop.
wslpath -w for new file
#!/usr/bin/env bash
# Useful for specifing new WSL file path to save by vscode
function winpath() {
file_path=$(wslpath -a "$1") # Absolute path (full path)
file_basename=$(basename "${file_path}")
file_dirname=$(dirname "${file_path}")
if [ "$#" -eq 0 ]; then
wslpath -w .
elif [ "$#" -eq 1 ]; then
# Also works for new files
echo $( wslpath -w "${file_dirname}" )"\\"${file_basename}
else
wslpath -w "$@"
fi
}
winpath "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment