Tag Archives: switch

go2: The obvious name for the tool

Last year’s avalanche of directory-switching tools is still reverberating in my ears. I would never assume I found them all, but I am pleased that I’ve found so many. Here’s go2, which is another of the same vein.


go2 is a clever name, since your effectively asking to “go to” some place else. I can appreciate a witty name … although the more I think about it, maybe it’s not so much witty as it is obvious. šŸ™„

Append go2 with a string and it will try to find a directory in your tree that matches it. Give it the -r flag and it will search through all your root directory, which makes it quick and easy to jump across wide chasms in your system.

The first time you run go2, it will fit itself into your .bashrc, and from then on you can access its finer features without any hassle. Aside from that, I saw very little configuration that go2 needed.

If go2 runs into a situation where there is more than one option, it will prompt you for a choice. If your target is too fuzzy, that can take a little while.

go2 is in Debian, but I didn’t see it in Arch or AUR. go2 has a few other options that you might not see in other fast directory-switchers, but I will leave them to you to discover. To be painfully honest, cd and tab completion are usually enough for me.

If you need a little more oomph at the prompt though, this might be helpful.

cdargs: Changing directories, quickly and visually

I am an avid user of Midnight Commander, and I will admit I sometimes use it as a navigation tool, and not just as a file manager. By that I mean, I can oftentimes navigate to obscure folders more quickly with mc, provided the lynx-like navigation setting is enabled.

That lets right arrows descend into directories, and left arrows bounce back out. Press CTRL+O, and bingo, your shell is there, in the directory. So you have a four-way folder navigation tool and sometimes — not always, but sometimes — it works faster than tab completion.

I’ve seen similar tree navigation with other tools; ranger is the first one to come to mind. ranger’s speed and popularity both depend to some degree on its quick and nimble navigation.

So why not a tool that just navigates directories, and leave it at that? Why not cdargs?


I’m pitching navigation speed and yet I can’t really demonstrate that in a static image. You’ll have to imagine working your way through your own file tree with the arrow keys, quickly bounding between folders with the grace of a gazelle, finally punching the Enter key with authority, and making your selection. Very satisfying.

cdargs also has some bookmarking capability, so you can add hot links to folders you use often. And technically speaking, cdargs has two “modes,” one for the browser and one for the list, and you can switch between them with the TAB key. More high-speed high jinx.

cdargs itself is meant as a drop-in tool for the shell, so ideally you should hunt down the cdargs-bash.sh file or the cdargs-zsh.sh file that should be included, and source them to add that function. I can’t speak to the zsh version, but the bash script adds the cv command, which turns cdargs into a proper directory switching tool.

Just about the only other thing I think I should say about cdargs is, this might be a good tool for command-line newcomers. There’s a visual element here that will probably appeal to people who aren’t yet used to thinking of a file structure as a tree that needs to be traversed. Supplying this and explaining the up-down-left-right arrangement might save some time.

But other than that, I can’t find much more to say about cdargs; the man page and help flags will probably guide you toward menu-based fast directory switching enlightenment. I see this is in both Arch proper and Debian, so it’s quite prolific. …

Oh, wait: No color. šŸ˜¦ Oh well, nothing’s perfect. šŸ˜‰

bashmarks: The simple solution

We’ve been through plenty of fast-directory switchers, like j and j2, or z or popd and pushd, and a lot of others (and there are still more to come šŸ™„ ). But I don’t recall seeing something like bashmarks before, which lets you give a nickname to your path, and recall it in the future.

bashmarks works as a shell script you can either trigger through your .bashrc file, or source directly as you need it. The git package offers to “install” it to .local/bin, but I found it just as usable in its raw form, sourced with . bashmarks/bashmarks.sh whenever I felt I wanted it.

Once you’re hooked in, bashmarks gives you about five commands, all single letters that trigger or control nicknames to folders in your system: “s” saves a path, “g” goes to a path, “l” lists the bookmarks, “d” deletes one and “p” prints the path held in a bookmark.

And basically, that’s all.

kmandla@6m47421: /usr/src/nvidia-96.43.23$ l
downloads            /home/kmandla/downloads
home                 /home/kmandla
nvidia               /usr/src/nvidia-96.43.23

kmandla@6m47421: /usr/src/nvidia-96.43.23$ g home

kmandla@6m47421: ~$ g nvidia

kmandla@6m47421: /usr/src/nvidia-96.43.23$

bashmarks saves its data in ~/.sdirs, and I doubt anyone would complain if you wanted to hand-edit that file, and still move seamlessly around your system.

There are two big reasons I enjoy using this. The first is tab completion with bashmarks, which is such an obvious addition that it would be a huge mistake if it hadn’t been included. The difference between g d[TAB] to get to /home/kmandla/downloads and cd /h[TAB]/k[TAB]/d[TAB] is enough to make bashmarks a useful tool.

The other reason is more philosophical, I suppose: If I was going to create some sort of “fast directory switching” tool, it would probably work like this. It’s the most obvious solution to me.

I’ve seen a lot of other directory switching tools that use stacks or frequency or priorities to try and analyze and predict where I want to go. bashmarks takes the simple path, lets you assign names, and goes where you tell it. And it does that without compiling intricate binaries, background daemons or gnarled dependencies.

It’s even got a tiny bit of color. šŸ˜‰

And since I’m feeling generous today, and because it does such a bang-up job, I’m going to give out a K.Mandla gold star to bashmarks: ā­ Don’t spend it all in one place. šŸ˜‰ Enjoy!

v: Re-edit files quickly with vim

When you think about it, rupa‘s v is a rather obvious little tool.


v skims through your .viminfo file, plucks out the paths and names of files you recently edited, and then offers them back to you in a menu. Select one, and vim re-opens it for editing, no matter where you are in your tree.

Nothing fancy, and an idea that’s probably fairly easy to figure out. v adds a few bonus tweaks, allowing you to automatically jump to number N on the list, with v -N. Files are ordered from latest to oldest, meaning v -1 is always the last file you opened.

It’s also possible to filter the list of past files, or to include deleted files in the list.

v is simple and clever and straightforward, and if you work with vim exclusively but bounce around a lot, it’s likely to be useful.

Unfortunately — and there’s no practical way around this — I make a point of omitting any sort of vim history with set viminfo="" in my .vimrc. So unless I decide to change on that point, I’m afraid I personally won’t be adopting v any time soon. :/

popd and pushd: The original fast directory switching

I’ve run across more than one fast directory switcher in the past 15 months, most notably fasd and j and j2. What you might not know is that the bash shell comes with a primitive fast directory switcher … of a sort.

popd and pushd are built-in commands in bash (and zsh, I believe) that work with a manageable stack of directories that you can bounce between. And since it’s been a while since we actually dug in to one of these tools, it’s probably a good time for an in-depth look at pushd and popd.

Compared with fasd et al., pushd/popd may take a little getting used to. Here’s a simple example:

kmandla@lv-r1fz6: ~$ pushd /usr/share/
/usr/share ~

kmandla@lv-r1fz6: /usr/share$

When I use pushd and a directory, I bounce straight to that location, and the path is put into the directory stack. pushd by itself effectively swaps entry Nos. 0 and 1. Either way, pushd‘s output is the current directory stack, from left to right, zero on up.

I can check what’s in the stack and the order with dirs (I like dirs -v, personally).

kmandla@lv-r1fz6: /usr/share$ dirs -v
 0  /usr/share
 1  ~

kmandla@lv-r1fz6: /usr/share$

The stack works LIFO, meaning last-in-first-out: The last (or newest) item added to the the stack is the first one used.

Zero (or the leftmost entry) is your current directory; you can cd to a new location without interfering with the stack. I can also add another destination if I like.

kmandla@lv-r1fz6: /usr/share$ pushd /lib/kernel
/lib/kernel /usr/share ~

kmandla@lv-r1fz6: /lib/kernel$

Now I have three in the stack. If I want to bounce back to a previous directory, I use popd to “pop” out the zero entry and jump to No. 1 in the stack.

kmandla@lv-r1fz6: /lib/kernel$ popd
/usr/share ~

kmandla@lv-r1fz6: /usr/share$

Note that I jumped back to /usr/share, and that /lib/kernel was removed from the list. The whole stack shuffles up one space.

If I had a lot of directories in the stack, I could successively popd through them until I arrived back where I began, and the stack would be empty.

kmandla@lv-r1fz6: /home$ dirs -v
 0  /home
 1  /boot
 2  /lib/kernel
 3  /usr/share
 4  ~

kmandla@lv-r1fz6: /home$ popd
/boot /lib/kernel /usr/share ~

kmandla@lv-r1fz6: /boot$ popd
/lib/kernel /usr/share ~

kmandla@lv-r1fz6: /lib/kernel$ popd
/usr/share ~

kmandla@lv-r1fz6: /usr/share$ popd

kmandla@lv-r1fz6: ~$

It’s not ideal if you have a series of directories you want to keep, and it’s hard to imagine how it works if you’re trying to visualize it like “bookmarks.” It’s not really like that at all.

In fact, it might be easier to think of it like a stack of plates: You can “push” a plate onto the top of the stack, and then “pop” out whatever is on top.

And aside from pushing and popping, there are some rudimentary management tricks. You can use dirs -c to clear the stack, -l lists them longhand and -p prints them in plain form. Using a plus or minus displays the number of entries from the left or right in the stack, respectively. Remember again that the leftmost is No. 0, and they increment as you move to the right.

popd and pushd work differently with the plus or minus; popd “pops” out the Nth entry from the left with minus, and from the right with a plus. pushd rotates the stack a certain number of steps to the left or right, with plus or minus.

kmandla@lv-r1fz6: /home$ dirs -v
 0  /home
 1  /boot
 2  /lib/kernel
 3  /usr/share
 4  ~

kmandla@lv-r1fz6: /home$ pushd +1
/boot /lib/kernel /usr/share ~ /home

kmandla@lv-r1fz6: /boot$ pushd +2
/usr/share ~ /home /boot /lib/kernel

kmandla@lv-r1fz6: /usr/share$ pushd -2
/home /boot /lib/kernel /usr/share ~

kmandla@lv-r1fz6: /home$ pushd -1
/usr/share ~ /home /boot /lib/kernel

kmandla@lv-r1fz6: /usr/share$ dirs -v
 0  /usr/share
 1  ~
 2  /home
 3  /boot
 4  /lib/kernel

kmandla@lv-r1fz6: /usr/share$

Note that each time, the list was shuffled and the current working directory changed.

Final tip: If it annoys you that popd always dumps an entry off your stack, start relying on pushd +N, which will just cycle you through the list. And remember: pushd by itself just swaps Nos. 0 and 1 in the stack, effectively bouncing you between two directories. šŸ˜Ž Aha! You can thank me later. šŸ˜‰

“Modern” fast directory switchers might have more conventional features, but for sheer lightness and convenience, pushd, popd and dirs are reliable and useful. Not bad, for software that dates back to 1976. šŸ˜Æ

If you want more guidance, try the bash reference manual, or enter help with any of pushd, popd or dirs. The learning curve is not too steep, but it may take some getting used to.

Enjoy. šŸ˜‰