UNIX Tool Tip: cdargs
Mac OS X — 3 Jun 2008 14:22 — 648 days ago

A coworker just showed me the useful UNIX tool cdargs. It provides bookmarks for often used directories in the shell.

You can do something similar with shell aliases and pushd/popd, but I find this far more convenient.

It doesn’t seem to be in MacPorts, so I downloaded, compiled and installed the source package with these commands:

$ curl -s http://www.skamphausen.de/software/cdargs/cdargs-1.35.tar.gz | tar -xzf -
$ cd cdargs-1.35/
$ ./configure && make
$ sudo make install
Password:

$ cp contrib/cdargs-bash.sh /usr/local/bin/

$ echo ". cdargs-bash.sh" >> ~/.bashrc

Reopen the terminal window and you’ll get two new commands:

ca
creates a bookmark of the current directory
cv
displays the list of bookmarks and changes the directory if you pick one.

Here’s cdargs in action:

A bookmark consists of a directory path and a shortcut word. ca without argument uses the current directory name as shortcut. Sometimes that’s not what you want so you can explicitly choose the shortcut by passing it as argument:

ca arteria

cv without argument shows a list of all bookmarks and lets you choose a directory to change to. With a shortcut as argument, it changes immediately to that directory. This usage supports completion of the shortcut so you only have to type an unambiguous prefix and hit the tab and return keys.

The list view can do a few more things, for example

  • it supports vi-style h/j/k/l navigation
  • you can drill down into a bookmarked directory with the arrow or “l” key to enter some subdirectory directly
  • typing “v” edits the list in your text editor of choice
  • typing “d” deletes a bookmark from the list

Update 2008-08-31: I just submitted a port for cdargs to MacPorts, hopefully you can soon get it from there.

Comments
Posted by Pascal on 3 Jun 2008 21:49

Wow, very nice tip. I used to solve this problem using aliases, but this solution is much more elegant, thanks for that.

Posted by Alain on 12 Aug 2008 05:59

Vielen Dank für den Tip!

PS: Ich musste aber ". cdargs-bash.sh" in ".bash_profile" schreiben, das mit dem ".bashrc" funktionierte nicht.

Powered By blojsom