Skip to content

Instantly share code, notes, and snippets.

@iansu
Created March 30, 2015 23:03
Show Gist options
  • Save iansu/e2393a2100de6dfb0b0d to your computer and use it in GitHub Desktop.
Save iansu/e2393a2100de6dfb0b0d to your computer and use it in GitHub Desktop.
Bash cd hook
cd() {
if [[ $1 =~ ^[\.]{3,}$ ]]; then
# rewrite ... as ../../ etc.
directory="../"
depth=${#1}
for i in `seq 3 $depth`; do
directory+=../
done
builtin cd "$directory"
else
builtin cd "$1"
fi
}
@iansu
Copy link
Author

iansu commented Mar 30, 2015

cd ... goes up two levels, cd .... goes up three levels, etc.

Add to your .bashrc or .bash_profile and enjoy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment