Skip to content

Instantly share code, notes, and snippets.

@congyiwu
Last active August 29, 2015 14:15
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 congyiwu/1ba22514a613d145e1ac to your computer and use it in GitHub Desktop.
Save congyiwu/1ba22514a613d145e1ac to your computer and use it in GitHub Desktop.
bashism free wrappers for cd and pwd for git-sh-setup
pwd () {
if test -z "${PWD#/[a-z]}"
then
#e.g. '/c' -> 'c:/'
echo "${PWD#/}:/"
return
fi
pwd_after_drive="${PWD#/[a-z]/}"
if test "$pwd_after_drive" != "$PWD"
then
#e.g. '/c/dir' -> 'c:/dir'
pwd_drive="${PWD%$pwd_after_drive}"
pwd_drive="${pwd_drive%/}"
pwd_drive="${pwd_drive#/}"
echo "${pwd_drive}:/$pwd_after_drive"
return
fi
#e.g. '//computer/share' -> '//computer/share'
command pwd
}
cd () {
if test -z "${1#[a-z]:}"
then
#e.g. 'cd c:' -> 'cd /c'
command cd "/${1%:}"
return
fi
if test -z "${1#[a-z]:/}"
then
#e.g. 'cd c:/' -> 'cd /c'
command cd "/${1%:/}"
return
fi
after_drive="${1#[a-z]:/}"
if test "$after_drive" != "$1"
then
#e.g. 'cd c:/dir' -> '/c/dir'
drive="${1%$after_drive}"
drive="${drive%:/}"
command cd "/${drive}/$after_drive"
return
fi
#e.g. 'cd /c' -> 'cd /c'
#e.g. 'cd /c/dir' -> 'cd /c/dir'
#e.g. '//computer/share' -> '//computer/share'
command cd "$1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment