Tag Archives: fast

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.

2015-02-10-r8-0acre-go2

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?

2014-11-05-2sjx281-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!

z and z: A tale of two z’s

Remember my little rant from a few weeks ago, the one about single-character application names? If you don’t it’s just as well. I usually regret my rants. That one was no exception.

The point comes through though, since I have two z’s to report — this one and this one.

2014-07-05-6m47421-z-01 2014-07-05-6m47421-z-02

The z on the left is an intuitive compression-decompression tool. By all rights it should sense whether a file should be compressed or decompressed, and come up with the right results. If you remember atool or dtrx or unp, think of it as one of those, with enough smarts to do the opposite, if need be.

I did run into a few problems with z — the z on the left, that is. Compression seemed to sputter in the Arch version, while it looked for something called compress at /usr/bin/. It wasn’t finding it, and so half of what it could do, it couldn’t.

The z on the right is another fast directory switching tool. It’s by the same author as j and j2, and seems to follow the same pattern.

If you place the z.sh script somewhere in your $PATH, and change the $_Z_CMD variable to just “z”, then you should start building a database of recently visited directories. From there you can jump straight to a particular one by prefixing it — or part of it — with just “z”.

In theory, of course, and there is more to it than just that. It works acceptably well, although personally I’m not much of a fan of fast-directory-switcher-gizmos, and so a lot of it is probably lost on me.

So there are the two z’s, and I’d like to just take one last second to remind everyone out there who is working on building The Next Great Killer App, The Program That Will Change Life As We Know It, The Application That Consumed The Entire Universe In One Slobbery Gulp, to please — please — think rationally for just the briefest moment, and give your program a name that’s longer than just one stupid letter. ๐Ÿ˜ก

v: Re-edit files quickly with vim

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

2014-06-14-6m47421-v

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. ๐Ÿ˜‰

j and j2: More fast directory switching

I’m going to combine j and j2 today, mostly because they’re both by the same author, and one is a rethink of the other … which says to me they are close enough in behavior to warrant a lump post.

2013-12-10-lv-r1fz6-j 2013-12-10-lv-r1fz6-j2

As you can see, I had a lot better luck with j and j2 than I did with autojump or fasd.

I like j2 in particular, for giving you the chance to use two arguments as a filter to pin down a particular directory.

It looks like neither of these has been updated in a while, but they still work fine. I should mention that j2 apparently relies on some python. Old, old machines might suffer with that.

Straight j, on the other hand, is just a shell script, so that might work better for you, or prove more portable. Either one is worth a look.