Search

cdargs: a browser for cd

April 5th, 2009 edited by Vicho

We have run out of articles! Please submit good articles about software you like!

cdargs is a command that enhances the good old cd by adding bookmarks and a browser. Sometimes you need to work on directories that are difficult to reach, even with the help of tab-completion (e.g. /var/www/mysite.com/subsection/includes). When you are in one of such directories, just type ca wwwinc and you’ll add a bookmark of the directory with the name wwwinc. Whenever you want to go back to that directory, no matter which is your current working directory, just type cv wwwinc and you’ll be back there. cdargs has tab-completion too and understands subdirectories of bookmarks. In the previous example, typing cv wwwinc/foo will be equivalent to cd /var/www/mysite.com/subsection/includes/foo

cdargs has a browser. Just type cv and cdargs will bring you a list of your bookmarks. You can use the arrow keys (or h, j, k and l if you are used to vim) to navigate the list. When you have selected your final directory hit enter, and you’ll return to the command line, in that directory. You can add new bookmarks by hitting ‘a’ and you can edit your list of bookmarks with your favorite editor hitting ‘e’. With ‘?’ you get a list of all of the available commands in cdargs.

cdargs browser

The bookmarks of cdargs can be extended to other commands. The distribution of cdargs provides examples for the commands cp and mv, under the aliases cpb and mvb. For example, if you want to copy the file bar to the bookmark in the previous example, a quick cpb bar wwwinc will do the trick.

cdargs needs some aliases in the shell to work correctly. If you use the bash shell, you need to add this to your ~/.bashrc:

if [ -e /usr/share/doc/cdargs/examples/cdargs-bash.sh ]; then
  . /usr/share/doc/cdargs/examples/cdargs-bash.sh
fi

The aliases are also available for tcsh, but not for zsh. The author is looking for someone who knows zsh shell scripting to write them.

Other alternatives

  • pushd, popd they are useful, but they are stack based and don’t provide any bookmark functionality.
  • CDPATH You can achieve a similar behavior using the shell variable CDPATH, symbolic links and aliasing cv to cd -P. However, the bookmarks are easier to maintain with cdargs and the browser is a nice way to navigate through the filesystem. Moreover, with CDPATH you can’t extend other commands as cdargs does with cp and mv.

Availability

cdargs has been in Debian since at least Sarge and in Ubuntu since at least Dapper.

Posted in Debian, Ubuntu |

9 Responses

  1. Omari Says:

    One could probably hook this into zsh, as the author requests. But zsh already has a feature called “named directories” which is so similar to cdargs that I doubt a zsh user would use cdargs. In zsh all you have to do to remember your current directory is set a parameter:

    remember=$PWD

    Then to change back to it later you just do

    cd ~remember

    If your prompt is set up right, the name you gave to the directory will even show up in your prompt.

  2. Sitaram Says:

    also try apparix; http://www.micans.org/apparix/

  3. Max Says:

    Did you actually try cdargs before writing this post? On Intrepid. it just doesn’t work. Hitting enter on any bookmark will just leave me in $HOME.

  4. Vicho Says:

    Max,

    You’re right. In order to launch the browser, you should type “cv” and not “cdargs”. I’ve corrected the article.

    It works in Debian. I haven’t tried it in Ubuntu, but it should work.

  5. Vicho Says:

    Omari, I might be wrong, but named directories don’t work accross sessions in zsh. If I do:

    remember=$PWD

    in one terminal and then switch to other terminal, it says:

    zsh: no such user or named directory: remember

    However, in cdargs, it just works.

  6. JosefA Says:

    Same as with Max, it just doesnt work in ubuntu. cdargs certainly launches the browser, but hitting enter on entries doesn’t change the directory.

    And there’s no ca or cv or cpb commands here.

  7. Yoav Says:

    JosefA, Max,

    As mentioned in the article, you have to add some lines to your .bashrc for cdargs to function properly. Simply apt-get install cdargs is not enough. After adding those lines cdargs work as promised on ubuntu.

    Thanks for a great article!

  8. Guy Says:

    this is great, I’ve been looking for something like this for ages! I’ve suggested to Dreamhost that they install it on all shell accounts.

    Thanks a lot :)

  9. Stephen Says:

    The pushd/popd functions’ usability is limited by the stack nature of the implementation. I have some ksh/bash functions that stuff the dirs stack into the login shell’s argv array. That way, $1 is the current directory, $2 is the next one in, $3 is the next, up to $9. And, i have the quicker alias “pd” for “pushd”, though either work OK and do everything i expect.

    Then there are convenience functions like “dif2″, “cmp2″, “mv2″. … You’d say “dif2 foo.txt”, and it would execute “diff -c -b foo.txt $2/foo.txt | less -c”. Though my new favorite tool is kompare. “dif2″ got me through decades.

    I didn’t invent this system. I’ve been using them, or something like them, since about 1983. Back then, i was using csh. I’ve not used csh or tcsh in decades - the idea being that ksh (and now bash) had a good enough UI, and i didn’t want to be tempted to write scripts in csh just because i knew it better. But i never throw anything out, so i probably have the csh/tcsh implementation kicking around somewhere. It shouldn’t take too long to find. There are only about a million (1,000,000) files in my home directory.