I spend quite a bit of time moving around in the terminal. Naturally, tools like fasd, bd, fzf, etc are at the top of my 'day-to-day usage list'. Unfortunately, zsh is nowhere among them. As much as I would love to use it, the majority of Linux distributions still don't have it preinstalled. For me it's a deal breaker. I honestly don't want to get homesick every time I
ssh into some remote machine I have no control over. The obvious shell of choice, given the circumstances, is Bash. Up until recently, there was one thing driving me nuts, though. Namely, absent zsh-style
cd. But, with commacd in the game, it's no longer a problem.
So, what is
commacd exactly? Well, it's basically just a bunch of aliases (
,,, and (surprise, surprise!)
,,,), designed to make navigation faster. The best way to explain each one of them is probably to go through some examples.
Let's start with
,. Think of it as a
cd that matches directories by prefixes:
If you often find yourself using
cd ../.., ... (in one from or another), you might be interested in
,,. It has a number of different strategies that can make navigation backward a whole lot easier:
- (no arguments) look for the project (checkout) directory (the one with .git/.hg/.svn in it) and then
- (one argument)
cdinto the closest parent having its name begin with whatever the value you passed in;
- (two arguments) replace all occurrences of the first value with the second one (in the current path).
The last one is
,,, (my favorite). Think of it as
, but from the first (nearest) parent directory having non-empty expansion. It allows quickly jump between multiple directories sharing the same ancestor (not necessarily an immediate one).
Note that all three commands automatically emit
pwd before the completion (just like
cd -), which makes it possible to combine them with other tools (without actually changing the working directory):
You can also hit
<Tab> whenever you want to check where are you about to jump to. Like this:
To shrink path back use
And now, the final part - installation.
commacd is written in pure Bash (no dependencies on Python/Ruby/Perl, no nothing). Getting it into your shell is as easy as:
After that, open a new terminal session and
Want to help out? Report issues, suggest improvements/features or, even better, send in a pull request (see GitHub page). Every bit is helpful.