Friday, April 23, 2010

BashMarks: Bash directory bookmarking tool

So I was working in Bash with a rather convoluted project recently and the large nesting convention of the directories was really annoying. I just couldn't keep everything straight. I was constantly switching between 4, 5 and 6 directories up and back. I went looking for a directory bookmarks tool and a few popped up on my radar. Notably:


http://www.ccrnp.ncifcrf.gov/~toms/nowhere/

After checking that out I thought, well it's alright but quite a bit limited too. I don't want a universal database holding all of my bookmarks in my ~/. What I really wanted was a bookmark directory that was only a pro pos in the current context. This has the benefit of contextual focus and minimizing mnemonic collisions. So I invented my own.


I call it BashMarks. So I kind of stole some of the conventions of the aforementioned tool (bm, bms in particular).

BashMarks

Installing it is easy. Just place it in your ~/bin/ folder (which must be in your PATH), and add the line

source ~/bin/bashMarks

to the end of your ~/.bashrc file. Voila! Instant bookmarking.

Quick Summary of features:
  • bm MNEMONIC [DIR] - bookmark a directory named MNEMONIC (DIR may be relative or absolute, and if not specified is pwd)
  • bml MNEMONIC - bookmark the *last* directory you were in
  • bms - recursively search backwards up the path looking for .bookmarkDB and list contents
  • g MNEMONIC - "go" to directory tagged MNEMONIC (note recurses up dir-tree looking for .bookmarkDB)
  • p MNEMONIC - "pushd" to directory tagged MNEMONIC (ditto recurses searching all parent .bookmarkDB(s))
  • g,p supports Bash autocompletion! Try tabbing out commands, or tabbing out to get a list of what bookmarks are available!


Note: there is nothing to create a new database as it's a very simple file, simply "touch .bookmarkDB" in any current or parent directory of your choice.

Also note: currently doesn't support spaces in directory names (who uses those anyway!)