Last active
September 22, 2016 10:59
-
-
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.
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
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[@]}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
WIN_USER
.source .zshrc
wcmd notepad foo.txt
and save.