Skip to content

Instantly share code, notes, and snippets.

@kafene
Forked from mbadran/gist:130469
Last active December 21, 2015 04:08
Show Gist options
  • Save kafene/6246945 to your computer and use it in GitHub Desktop.
Save kafene/6246945 to your computer and use it in GitHub Desktop.
silent pushd (aliased to cd)
function cd {
if (("$#" > 0)); then
if [ "$1" == "-" ]; then
builtin popd >/dev/null
elif [ "$1" == "--" ]; then
dirs -v
return $?
elif [ "$1" == "." ]; then
# break out of symlinked dir (cd into realpath)
builtin pushd "`pwd -P`" >/dev/null
else
builtin pushd "$@" >/dev/null
fi
else
builtin cd "$HOME" >/dev/null
fi
[ $# -ne 0 ] && builtin cd "$1"
pwd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment