| Sunday May 29th 2016

Command Line Bookmarks using bm

bm is a program that can make life at the terminal a little easier when you often have to deal with a couple of directories at the same time. It can be used to keep bookmarks of directories you use regularly, but are a drag to type and switch between.

Of course, there are the popd, pushd and dirs commands, but a stack is often not sufficient to work fast. That’s why I wrote bm…

bm is a tiny program written in C that reads from a simple, clear text bookmark text file to generate an index. All you need to do to set it up is type the following in a terminal:

wget http://www.onderstekop.nl/coding/25_bm_1.0rc1.tar.gz
tar -xvf bm-1.0rc1.tar.gz
cd bm-1.0rc1
make && sudo make install

Now you can type the bm command and it will show you nothing, because you haven’t added any bookmarks yet. Lets add the current directory:

$ bm -a
0. /home/bspaans/bm-1.0rc1

The directory has been added! Lets add another one:

$ bm -a /var/log/apache2/
0. /home/bspaans/bm-1.0rc1
1. /var/log/apache2/

As you can see we have built up a very small index. Using the index as the only argument we can now get the data out and use it with cd, for instance.

$ bm 0
$ bm 1
$ cd `bm 1`

This works, but the backticks get a little tiring. It would be nicer if we could just type something like:

$ cdbm 1

And be done with it. This is possible by adding a tiny function to your ~/.bashrc script:

function cdbm { cd "`bm $1`"; }

And that’s it! You can see more options by using the –help switch or by reading the README.


Related Posts: On this day...

Leave a Reply

You must be logged in to post a comment.