Sunday, September 11, 2005

hacking the command line

I love the command line shortcuts, and I was looking for information about the 'cd history'. So I found pushd and popd. The pushd builtin adds directories to the directory stack as it changes the current directory, and popd removes directories from that stack changing the current directory to the last directory removed. To see the stack directory just:
$ echo $DIRSTACK 
or
$ dirs
If you are writing code on ~/Projecs/macaco/src and now need to jump momentarily to ~/Projects/Nazca, just 'pushd .' and when you finish your tasks on ~/Projects/Nazca do 'cd ~/Projecs/macaco/src'. Actually, you can store more than one directory at a time, remember, it is a stack (you can also use FIFO instead LIFO using unix pipes)

Tuning you box

Add to /.bashrc the next lines:
#redefine pushd and popd so they don't output the directory stack
# the output is redirected to /dev/null to prevent displaying the 
# dir stack when they are called
pushd()
{
    builtin pushd "$@" > /dev/null
}
popd()
{
    builtin popd "$@" > /dev/null
}

#alias cd so it uses the directory stack
alias pd='pushd'
#aliad pb as a command that goes one directory back in the stack
alias po 'popd'
# 
#To rotate between directories
alias r "pushd +1"
alias rr "cd "$OLDPWD"