Skip to content

Instantly share code, notes, and snippets.

@gohkhoonhiang
Last active August 9, 2016 07:40
Show Gist options
  • Save gohkhoonhiang/14d95dffe759af17ad951e950edb8ce6 to your computer and use it in GitHub Desktop.
Save gohkhoonhiang/14d95dffe759af17ad951e950edb8ce6 to your computer and use it in GitHub Desktop.
# shortcut to a declared environment variable to a directory
# eg. declare myrepo=~/Documents/repo
# then do 'to myrepo' will be equivalent to 'cd ~/Documents/repo'
function to() {
if [ -z "$1" ]; then
echo "Empty argument"
return
fi
eval temp_var=\$$1
if [ -z "${temp_var}" ]; then
echo "Shortcut not found"
return
fi
cd $temp_var
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment