Skip to content

Instantly share code, notes, and snippets.

@1ace
Created November 3, 2019 21:55
Show Gist options
  • Save 1ace/9eb03ab2f4f291d8662674d03f58f4b3 to your computer and use it in GitHub Desktop.
Save 1ace/9eb03ab2f4f291d8662674d03f58f4b3 to your computer and use it in GitHub Desktop.
cd() {
if [ $# -gt 1 ]; then
echo "cd: too many arguments" >&2
return 1
fi
if [ -d "$1" ]; then
pushd "$1"
elif [ "$1" == "-" ]; then
popd
elif [ "$1" == "--" ]; then
pushd
elif [ "$1" == "---" ]; then
while popd -n &>/dev/null; do :; done
dirs
elif [ $# -eq 0 ]; then
dirs
else
echo "cd: $1: No such file or directory" >&2
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment