CDargs Brings Bookmarks to the Linux Command Line

1092

 

Reducing keystrokes isn’t the only path to productivity, but it certainly helps. If you find yourself visiting the same directories on your system (or systems) every day, save yourself some time and bookmark your most frequently used directories with CDargs.

Even with tab completion, moving around the filesystem at the command line can get tedious. For instance, I use Dropbox to store all my work files, and organize my files by client or project. So, for example, I keep my Linux.com stories under Dropbox/Documents/Stories/Linux.com and my invoices under Dropbox/Documents/Invoices. I could type cd ~/Dropbox/Documents/Stories/Linux.com every time, or create a symlink or alias that would be shorter, or just install cdargs and make life easier.

You can find CDargs on most Debian-based distros, so if you’re using Debian, Linux Mint, or Ubuntu you should be able to just grab it with sudo apt-get install cdargs. It’s also available on Fedora, and you should be able to find it through the openSUSE Build Service as well.

Once you’ve installed CDargs, you’re also going to want to add a script to support your favorite shell. Assuming your favorite shell is either GNU Bash or tcsh. On Debian-based systems, this is located under /usr/share/doc/cdargs/examples. Since most users are working with Bash, we’ll look at that one. You’ll need to source the file cdargs-bash.sh to use most of the shortcuts for CDargs that I’ll explain in this tutorial.

You can do this once with source /usr/share/doc/cdargs/examples/cdargs-bash.sh, which is fine for following along with this tutorial. The problem with that is that it only takes effect for the duration of the session you’re running. When you log out of that shell, Bash won’t know about the script and so you’ll have to source the file each time. Or you can simply add this to your ~/.bashrc:

 

source /usr/share/doc/cdargs/examples/cdargs-bash.sh

 

If there’s no .bashrc in your home directory, go ahead and create a new file by that name.

Using CDargs

Now it’s time to start using cdargs. First, let’s add a bookmark for a directory you use often. Go ahead and cd to any directory you use frequently and then add it to your list of bookmarks with ca shortcut. So, for instance, I’d use ca Lc to add ~/Dropbox/Documents/Stories/Linux.com to my bookmarks. Now I have a bookmark with the name Lc that I can use to move to that directory.

You can use the bookmark in a number of ways. Running cdb Lc is the fastest path. But what if you’ve forgotten what name you’ve given a bookmark? No problem. Run cv and you’ll be able to see the entire list of bookmarks. It will look something like this:

 

 0 [Lc       ]  /home/jzb/Dropbox/Documents/Stories/Linux.com
 1 [stories  ]  /home/jzb/Dropbox/Documents/Stories
 2 [Documents]  /home/jzb/Dropbox/Documents
 3 [ff       ]  /home/jzb/local/firefox
 4 [LP       ]  /home/jzb/Dropbox/Documents/Stories/LinuxPro
 5 [lwn      ]  /home/jzb/Dropbox/Documents/Stories/LWN
 6 [dwld     ]  /home/jzb/Downloads

 

At the bottom of the terminal, you should also see a L: or B: to indicate whether you’re in list or browse mode. By default you should be in list mode when you run cdb. Here you can select any of the bookmarks, or add new ones (press a) or delete bookmarks by highlighting the bookmark you want to remove and pressing d.

While in cdargs you can also browse the filesystem and look for directories to add. Actually, you can also use cdargs as a browser for directories, so you don’t need to type out full directory names. For example, run cv in your home directory and hit Tab. Now you’ll see a B in the bottom bar and a listing of all the sub-directories in your home directory. You can now use the arrow keys to browse through the directory structure. Vim users will also feel right at home, as you can use the h,j,k,l keys to move left, up, down, and right, respectively. Hit Enter to exit cdargs and be placed in the directory you’d browsed to.

Note that cdargs doesn’t display hidden directories by default, but you can change that by typing . — which should be easy to remember. Just type . to see hidden directories, which begin with the dot. Finally, you can see all the movement commands and such while in cdargs with H, and exit with q.

Simple, no? CDargs is not a complex application, but it’s quite a time-saver if you become disciplined about using it. Let’s recap with a quick summary of the most useful commands:

  • ca bookmark – Add a bookmark with the name bookmark.
  • ca – When used with no argument, will add the current directory to your bookmarks with the name of the directory as the name of the bookmark.
  • cdb bookmark – Move to the directory bookmarked with the name bookmark
  • cdb – When used without an argument, will take you to the browser to pick from the bookmarks.
  • cv – Like cdb. Opens CDargs’ browser.

It takes about ten minutes to install cdargs and another ten or so to add the directories you use most often. The only downside I’ve found with CDargs is that it’s designed with a single computer in mind. If you use multiple computers, you have to install and configure it on each, which can be a bit of a headache. If you have two (or more) computers set up similarly, note that you can copy the bookmarks file that is stored under your home directory as .cdargs. It’s a shame that something this useful (and relatively obvious) isn’t a default part of GNU Bash at this point, but at least we have CDargs. Enjoy!