Bookmarking Directories in Bash
Well not in the same sense as bookmarking in your web browsers. But what it does do is make it easy to jump to the many directories that you may commonly visit.
[block:important]I'm no pro at bash, but this is a simple solution I came up with and thought others may benefit from it.[/block]
Some directories I would may occasionally visit:
/opt/local/lib/ruby/gems/1.8/gems//Users/aizat/src/projectA/User/aizat/src/companyB/projectC/User/aizat/src/companyB/projectD
I may use the bash expansion ~/ to easily go to my home directory, but I'm still rather limited in what I can access.
So here is a simple gem you can place in either your ~/.bashrc, or ~/.bash_profile
[block:file]
function bookmark {
case "$1" in
projectA) pushd /Users/aizat/src/projectA ;;
projectC) pushd /Users/aizat/src/companyB/projectC ;;
projectD) pushd /Users/aizat/src/companyB/projectD ;;
gems) pushd /opt/local/lib/ruby/gems/1.8/gems ;;
*) echo "forgot something?" ;;
esac
}
[/block]
Replace as required with your own directories, but don't remove the line with the asterisk!
Before you start using the function, you have to either start a new bash session, terminal, or execute source ~/.bash_profile. Which ever fancies you.
So in your bash session, try it out.
[block:terminal]
bookmark projectA
bookmark gems
bookmark projectC
bookmark projectB
[/block]
Now you can easily jump directories in convenience! But wait, oops! Did you accidently go to the wrong project? Want to easily go back to your previous directory? No problem. Since we used pushd, its as easy as a popd away!
Don't forget tab completion, so you don't have to type the code bookmark command!
[block:important]Know something even more convenient? Do share![/block]
