Directory Jumping With Perl
Posted on September 2nd, 2007
I hate navigating a directory tree. The same scenario plays itself
out over and over: you're working on some files in Directory A, and
everything starts out great. But then you need to refer to some files
in Directory B, which is in some other location and not at all
convenient to get to. Your brain shifts to the task of navigation. You
mouse click or cd your way to wherever Directory B
is. That's the point of annoyance-- changing contexts isn't
fluid. It's even worse if you're dealing with multiple applications
who have their own notions of where "here" is. Save this file to
whatever random directory I was working in last time that has no
bearing on what I'm doing now? Why sure, how did you know?
My directory jumping script is similar to the script I wrote about
in A
Spotlight Alternative With Perl, but it's for visiting directories
rather than launching applications. It starts off with a file called
.jump_includes.txt in your home directory, which contains
a list of root directories to scan. In my case I have things like
/var/www in here, as well as my documents folder and
handful of others. Next there's .jump_excludes.txt, which
should be a list of directories to ignore. Things like
.svn directories go in this file, since you don't
normally have occasion to interact with them and in terms of
navigation they're just distracting dead ends.
When jump.pl is given --crawl as its sole
argument, it'll scan the directories listed in the include file and
write a cache file in your home directory. By grepping through this
cache file, jump.pl can identify the path that best
matches your input. If there's any ambiguity, it'll prompt you in a
"did you mean..." fashion with a list of possibilities.
This is better than tab-completion on the command line, because you
get the whole path in one shot. And it absolutely saves on mouse
clicks. I currently have things set up with OS X in mind, so that
jump.pl --cd destination will open a new Terminal window
and drop you into the specified folder and jump.pl --open
destination will open a new Finder window. It wouldn't take
much to accommodate other platforms. Best of all, a single-letter bash
function can wrap the call to jump.pl and keep typing to
a bare minimum.
This doesn't solve the problem of Applications being in different directories than you want them to be when opening or saving files, but it does make it easier to move around without keeping mental track of folder paths.
Jump.pl can be found here.