Skip to content

Instantly share code, notes, and snippets.

@coldnebo
Created August 18, 2011 18:44
Show Gist options
  • Save coldnebo/1154804 to your computer and use it in GitHub Desktop.
Save coldnebo/1154804 to your computer and use it in GitHub Desktop.
bash helper to navigate directory stacks
# I use pushd and popd to maintain a directory stack and so I like being able to navigate
# around the stack with the cursor keys. Here's how:
# 1) pushd <new dir>
# 2) use CTRL+UP, CTRL+LEFT or CTRL+RIGHT as follows:
# bind ctrl + cursor keys:
# left = prev; right = next; up = list
bind '"\e[1;5A":"dirs\C-m"'
bind '"\e[1;5D":"pushd -0 2>/dev/null\C-m"'
bind '"\e[1;5C":"pushd +1 2>/dev/null\C-m"'
@timfriske
Copy link

# I put similar key bindings in my .inputrc file. This place is more suitable to bind keys to GNU readline's functions and macros.
# Here is what the bound keys do:
#
# <ctrl>-^: toggle the two directories from the top.
"\C-^": "\C-a\C-kpushd\C-m"
# <alt>-<: change to the second from top directory.
"\e<": "\C-a\C-kpushd +1\C-m"
# <alt>->: change to the bottom from top directory.
"\e>": "\C-a\C-kpushd -0\C-m"
# <alt>-x<alt>-<: pop the top changing to the second from top directory.
"\ex\e<": "\C-a\C-kpopd +0\C-m"
# <alt>-x<alt>->: change to the bottom from top directory and pop the former top.
"\ex\e>": "\C-a\C-kpushd -0; popd +1\C-m"

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