Skip to content

Instantly share code, notes, and snippets.

@sujoyu
Last active September 22, 2016 10:59
Show Gist options
  • Save sujoyu/0d3603623c753eaafb628c991ccd928d to your computer and use it in GitHub Desktop.
Save sujoyu/0d3603623c753eaafb628c991ccd928d to your computer and use it in GitHub Desktop.
Windows path to WSL(Bash on Ubuntu on Windows10) path convertor for cbwin( https://github.com/xilun/cbwin ) written with zsh.
WIN_USER=john
LINUX_ROOT="C:\\Users\\$WIN_USER\\AppData\\Local\\lxss\\"
alias wcmd=to_win_path
to_win_path() {
join_by() { local IFS="$1"; shift; echo "$*"; }
local IFS narg arg dirnames
narg=()
for arg in ${@:2}; do
abs=${arg:a}
IFS='/' read -rA dirnames <<< "$abs"
dirnames=(${dirnames[@]})
if [ ${dirnames[1]} = "mnt" ]; then
local tail_path=$(join_by / "${dirnames[@]:2}")
narg+=(\"${dirnames[2]}\:\\${tail_path:gs/\//\\/}\")
else
narg+=(\"$LINUX_ROOT${abs:gs/\//\\/}\")
fi
done
command wcmd : "$1" "${narg[@]}"
}
@sujoyu
Copy link
Author

sujoyu commented Sep 22, 2016

Usage

  1. Add this script your .zshrc.
  2. Set your Windows user name WIN_USER.
  3. source .zshrc
  4. wcmd notepad foo.txt and save.
  5. foo.txt created at current directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment