Developer Aspirations

YAPB - Yet Another Programming Blog

Monday

07

April 2014

Upgrade Your Command-Line - Part 1: Bashmarks

by Colin Miller, on command-line, bash, bashmarks

A few years ago I was complaining to a coworker how frustrating it was to always type out these long paths to particular directories that I needed to access. For instance I might need to access some http logs in /var/log/http/custom_server/backlog/. After looking at the logs I might go back to my project that resides in /home/cmiller/Projects/android/LinkedIn/. A shortcut if that was my last directory is to just use cd -, however I've often changed around different directories and I can't just use the shortcut. My coworker introduced me to bashmarks, and it's one of the first things I install on any new machine.

Bashmarks are easy to use bookmarks for bash. It comes with 5 commands. If I'm in a directory that I use often and want to create a bashmark to it, I simply use the s command:

[/home/cmiller/Projects/android/LinkedIn/] $ s android

I have just saved the path /home/cmiller/Projects/android/Linkedin/ to the bashmark android. To get to that directory I can simply use:

[/home/cmiller/] $ g android
[/home/cmiller/Projects/android/LInkedIn/] $

It even supports tab-completion so I can use g and<tab> and have it automatically fill in android for me.

If I want to see all of the bashmarks that I currently have saved, I can simply use:

$ l
android    /home/cmiller/Projects/android/LinkedIn

(that's a lowercase L). L lists all of the bashmarks I currently have saved. If I need to just look at the path of a single bashmark I can use:

$ p android
/home/cmiller/Projects/android/LinkedIn

While the p command might not seem as useful compared to the l command, it can be nice when combined with other commands:

$ cp newfile.png `p android`/res/drawable-hdpi/

This uses bash's backtick to insert the results of p android into my cp command and save me typing out a full path.

The last command is for deleting a current bashmark. As you might have guessed, it's used:

$ d android

And now my bashmarks are all cleaned up. It's an easy tool to add and can greatly speed up navigating around your system.

You can get Bashmarks at https://github.com/huyng/bashmarks

Next Up: Part 2: super cd ..

comments powered by Disqus