Bash navigation is made easy.

Moving between the folders in a bash shell is the most painful thing. How cool it would be to have bookmarks and cd to them without writing all the path name. So here is how you can add bookmarking functionality to your bash shell. works great and I use all the time.

# I got this from http://hayne.net/MacDev/Bash/aliases.bash
# and made few changes by my own
if [ ! -f ~/.dirs ]; then  # if doesn't exist, create it
    touch ~/.dirs
else
    source ~/.dirs
fi

alias L='cat ~/.dirs'

G () {              # goes to distination dir otherwise , stay in the dir
    cd ${1:-$(pwd)} ;
}

S () {              # SAVE a BOOKMARK
    sed "/$@/d" ~/.dirs > ~/.dirs1;
    \mv ~/.dirs1 ~/.dirs;
    echo "$@"=\"`pwd`\" >> ~/.dirs;
    source ~/.dirs ;
}

R () {              # remove a BOOKMARK
    sed "/$@/d" ~/.dirs > ~/.dirs1;
    \mv ~/.dirs1 ~/.dirs;
}

alias U='source ~/.dirs'    # Update BOOKMARK stack
# set the bash option so that no '$' is required when using the above facility
shopt -s cdable_vars

Put this code in .bashrc in your home directory, then you are good to go.

use S to save a bookmark and cd (or G) to your favorite folder. try these commands you can how easy it is. here $ is your shell PS.

$ mkdir myfavfolder
$ cd myfavfolder
$ pwd
$ S fav
$ L
$ cd
$ pwd
$ cd fav
$ pwd

My work flow is to add a “now” bookmark to current work folder and move around to any folder and come back with cd now current folder. If I found I am accessing two folders frequently to finish the task at hand, I would bookmark them as now and then with addition to all other bookmarks. It works very well for me. what do you think.?

By the way., there is a great bash pulgin called bash_it on github. I added this functionality there as well.