Jumping quickly between deep directories
16 Oct 2014I often need to jump between different directories with very deep paths, like this:
While it only takes a handful of seconds to switch directories, the extra mental effort often derails my train of thought. Some solutions exist, but they all have their limitations. For example, pushd
and popd
don’t work well for directories you haven’t visited in a while. Aliases require you to manually add a new alias to your .bashrc every time you want to save a new directory.
I recently found a solution, inspired by this post from Jeroen Janssens, that works great and feels totally natural. All it takes is a one-time change to your .bashrc that will allow you to easily save directories and switch between them. To save a directory, just use the mark
function:
To navigate to a saved directory, just use the cdd
function:
You can display a list of your saved directories with the marks
function, and you can remove a directory from the list with the unmark
function:
For any of this to work, you’ll need to add this to your .bashrc, assuming you have a Mac and use the bash shell.
This differs from Jeroen’s original code in a couple of ways. First, to be more brain-friendly, it names the function “cdd” instead of “jump”. Second, the tab completion works better.
Update: John McDonnell points me to autojump.