Searching Gradients




Bashmarks: Directory Bookmarks in the Shell

EDIT 2010-07-01 : This post is left up for context / historical posterity. I've packaged up a shell script to allow you to save and jump to commonly used directories. It's called bashmarks and it has tab completion functionality built-in. Visit the link below to learn more.

Bashmarks


Do not use the stuff below


Before I wrote this script, It felt like I spent half of my time in terminal cd-ing around to various directories. If you're like me, placing this snippet into your .bashrc file will save you tons of time each and every single day:

# Bash Directory Bookmarks
alias m1='alias g1="cd `pwd`"'
alias m2='alias g2="cd `pwd`"'
alias m3='alias g3="cd `pwd`"'
alias m4='alias g4="cd `pwd`"'
alias m5='alias g5="cd `pwd`"'
alias m6='alias g6="cd `pwd`"'
alias m7='alias g7="cd `pwd`"'
alias m8='alias g8="cd `pwd`"'
alias m9='alias g9="cd `pwd`"'
alias mdump='alias|grep -e "alias g[0-9]"|grep -v "alias m" > ~/.bookmarks'
alias lma='alias | grep -e "alias g[0-9]"|grep -v "alias m"|sed "s/alias //"'
touch ~/.bookmarks
source ~/.bookmarks

Directory Bookmark Usage

With this in place, your bash shell will have the ability to set and retrieve directory bookmarks. Let's say you're in a folder that you visit a hundreds of times per day. Run one of the "m" (a.k.a mark) commands inside the directory to create a bookmark. Here's an example:

# This will create a bookmark for the /var/www directory
user@host[/var/www/] : m1

Now whenever you want to cd into that directory, you can run the corresponding "g" (a.k.a goto mark) command.

# This will cd into /var/www
user@host[/etc/apache2] : g1

In other words the m1 command will set the g1 bookmark, the m2 command will set the g2 bookmark, and so on ... If you don't want to keep track of these bookmarks in your head, you'll be glad to hear that the "lma" (a.k.a "list marks ") command can show you all of your current bookmarks like so:

user@host[/usr/local/] : lma
g1='cd /var/www/'
g2='cd /etc/'

Persisting the Bookmarks

If you want to preserve your bookmarks for the next time you log in, execute the mdump command which will store the bookmarks into a file called .bookmarks under your HOME directory. Keep in mind that if you do not run this command your bookmarks will be forgotten once you log out of the shell.



Hey there! I'm Huy and I do research in computer vision, visual search, and AI. You can get updates on new essays by subscribing to my rss feed. Occassionally, I will send out interesting links on twitter so follow me if you like this kind stuff.






Show or Add Comments