Skip to content
joelthelion edited this page Sep 13, 2010 · 17 revisions

Spend a lot of time cd-ing around a complex directory tree?

j keeps track of where you’ve been, and how much time you spend there. Source it into your .bashrc, and then you can say j foo to jump to the most used directory that has the substring (actually regex) foo in it, or j foo bar for the directory that has both foo and bar

It tab completes out of its file ($HOME/.j), and tries a case sensitive match first, then tries to match without case sensitivity.

j by itself (or j --l) displays the current list of directories being remembered.

FAQ

How come j .. doesn’t work like cd ..?

j is not intended as a substitute for the cd command. You should still cd everywhere as you normally would. When you want to jump somewhere you have been, then type j substring to jump a directory in your often used list.

Why do the options for j use a double-dash -- instead of a single-dash -?

It’s quite possible you have directories named-liked-this. So we want you to be able to search for them using -. Directories named--like--this are less likely to be laying around, and quite frankly, I’d be mad at you for having them. A reasonable way to avoid the annoyance of typing --l, which is the only option intended to be used by a human, is to alias something to j --l, eg put alias jl='j --l' in your .bashrc. Alternatively, just say j by itself; j with no arguments is equivalent to j --l.

How do i “source” something? Why?

Short answer: instead of running the script as j.sh you type source j.sh or . j.sh in a shell, or to make it available all the time, put a command in your .bashrc that sources it, or just paste the contents of j.sh directly into your .bashrc.

Long answer: sourcing is like importing. When you run a script in a shell, it creates a subshell, runs your script, and returns to your current shell. If you cd in that subshell, it won’t matter to your current shell, because when your script is done running, it exits, and comes back to where you (still) are in your current shell. What we want in this case is to have the function and commands in our script defined in our current shell. Sourcing – rather than executing – the file does exactly that.

Editor Integration

j is such a good idea I want it everywhere! Coming soon: j.el provides emacs with its own version of j. It uses j.sh’s directory list to jump to a directory.