Skip to content

Instantly share code, notes, and snippets.

@superjer
Last active December 14, 2015 09:59
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 superjer/5068472 to your computer and use it in GitHub Desktop.
Save superjer/5068472 to your computer and use it in GitHub Desktop.
Easier directory navigation for Bash. Add to your .bashrc file. You can usually get where you need to be by just hitting Ctrl-O a lot, and avoid typing lots of cd this and cd that. See comments below for more info.
# Ctrl-P: go to parent dir (same as cd ..)
bind -m vi-insert '"\C-P":"\C-E\C-Ucd ..\C-M"'
bind -m emacs '"\C-P":"\C-E\C-Ucd ..\C-M"'
# Ctrl-O or Ctrl-B: go back to previous directory you were in
bind -m vi-insert '"\C-O":"\C-E\C-Ubackd\C-M"'
bind -m emacs '"\C-O":"\C-E\C-Ubackd\C-M"'
bind -m vi-insert '"\C-B":"\C-E\C-Ubackd\C-M"'
bind -m emacs '"\C-B":"\C-E\C-Ubackd\C-M"'
# Ctrl-F: go fwd a directory, retracing steps
bind -m vi-insert '"\C-F":"\C-E\C-Ufwdd\C-M"'
bind -m emacs '"\C-F":"\C-E\C-Ufwdd\C-M"'
alias backd='pushd +1 >/dev/null'
alias fwdd='pushd -0 >/dev/null'
cd () {
if [ "$*" = "" ]; then
pushd $HOME >/dev/null
else
pushd "$*" >/dev/null
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment