Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Autojump: a cd command that learns (wiki.github.com)
79 points by amix on March 28, 2010 | hide | past | favorite | 30 comments


For those of you who would like similar functionality sans learning of your MFU directories, you can do something like

export CDPATH=($HOME/common:$HOME/repos)

You'd have to manually symlink your favorite directories into ~/common, of course.

The directories listed in $CDPATH are made available to `cd` no matter what directory you are in, so if you have ~/common/downloads, you can type `cd downloads` from any directory. Tab-completion works with this too.

Not to downplay autojump -- I just prefer this approach since I explicitly control all the directories I want quick access to, and my `cd` command is deterministic (assuming I name directories to avoid conflicts).


My friend Rupa's 'z' utility - http://wiki.github.com/rupa/z/ - does this pretty nicely, too.

Discussed on reddit here: http://www.reddit.com/r/programming/comments/7y4ap/where_the...


z was inspired by autojump. It has a slightly different philosophy than autojump: while autojump is designed to be so simple that you forget about it after a while, z has more features and is slightly more complex. Using one or the other is mostly a matter of taste :)


I love z! It saves a lot of typing!


Much nicer than my solution: http://akkartik.name/bash.html#cd

Update: Ah, I knew there was another j a year ago: http://news.ycombinator.com/item?id=485053. (And I pushed my version there as well :/)


A patch to autojump that:

* Makes it possible to jump to a relative path (e.g. `j ../models`)

* Possible to specify multiple patterns, e.g. `j my_project static`

http://github.com/amix/autojump/commit/f5fff8d8c0c6e8ce676aa...


I've also found the CTRL-r shortcut quite helpful in Bash. Most of my commonly used directories and commands are near the surface this way, it works on almost everything without installation, and I'm usually in a directory where those commands would make sense.

Although, it doesn't really help if you need to jump to an obscure part of the filesystem.


Back in the 90's I used 4DOS on MS-DOS, which had a similar concept of 'jumping' to a directory by just typing the last part of a directory path. You had to pre-index your directory structure with 'CDD /S', though. And it didn't remember your favourite directories to give them priority.


I prefer cdargs http://www.skamphausen.de/cgi-bin/ska/CDargs

it doesn't learn, but rather you create bookmarks with simple aliases. The nicest part is that it's set up so you can tab-complete bookmarks and subsequent subdirs.


Just out of curiosity, have you used both? For how long?


I came across autojump a while back, but I have an aversion to 'learning' systems in that they can sometimes conflict with muscle-memory (you expect a certain thing to always perform a certain action, but through training it now does something different)

I've just reinstalled it to check out, and I've noticed a couple of things that I dislike:

1) it doesn't seem to consistently tab-complete (j <tab><tab> returns a bunch of __1__/some/path entries) 2) It's not easy to cycle through/view multiple matches 3) I'm not sure how to modify the database (eg: when I complete a project and archive stuff, I probably don't want to jump there anymore, even though it might be quite highly rated)

cdargs deals with most of these things in a better way, but doesn't have any of the learning features. I've used it now for a few months, and I'm in the process of hacking at it a bit to make it fit better into my workflow.

One useful tip that applies probably equally to both is to add something like:

"\C-f": "\C-a\C-kcdd \t\t"

into ~/.inputrc for a binding style completion.


About tab completion:

The bunch of __1__ entries are the best matches, and you simply need to add the number you want and another tab to finish the completion. It's a bit hackish, but it works fine! Maybe I should document this somewhere though :)

You can't directly edit the database, however autojump automatically removes directories that are not there anymore. Thus if you're done with a project, simply move the directory to archive/ or something, and autojump will forget about it. Otherwise the exponential decay works fast enough anyways.

I understand learning systems are not for everybody, though. With autojump, I tried to make the behavior of the system as predictable as possible, but it's not and will never be fully deterministic. I accept this as a necessary bad counterpart to the nice features autojump has, but I understand some people will never like it.


This reminds me of this blog post: http://unqualified-reservations.blogspot.com/2009/07/wolfram...

A few extra keystrokes is a good trade to get predictability.


I wrote my own utility which works a bit differently. Instead of calling cd, I call a different function which changes to a directory stored by an alias in a DBM database. Any time I'm in a directory that I know I'll want to revisit frequently, I call another function to save the current directory (by alias) to the database. Another shell function lists the current aliases in the database and what directories they point to.

It's a bit of a hack (a combo of Perl and bash scripting) -- something anyone on HN could probably put together in no time, but it does the job. I've been using it for 2 or 3 years now, and I find it to be extremely useful and a decent time saver.


Has anyone used this with OS X yet? I installed it manually and haven't been able to get it to work yet.


It runs for me, but I have no tab completion. Puzzling.

Edit: scratch that. I have tab completion of things in the database, but not of paths! Much, much less usable than cd for going to places I haven't been before, which is probably half of my usage. Oh well.


You're still supposed to use cd to go to places you've never been to! Autojump is a complement to cd, not a total replacement.


You need to add following lines into your .bash_profile and restart Terminal.app.

    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
      . ~/.bashrc
    fi


It works in OS X without any problems. I am using `zsh`.

Could it be because you haven't trained the database?


I think it should work on OS X, don't hesitate to contact me if you run into any problems.


I tried autojump (and/or something like it) for a short while, but essentially never found that I never remembered to use it/them. cd, cd -, tab completion, symlinks and screen/tmux are enough for me.


What about pushd and popd?


I'm aware of their existence, but the "hands" in my brain never "reach" for those tools. I find that when you have dozens of shells open in or around the directories you're working in, you don't change directories as much. Like the difference between leaving files open versus closing them and reopening them all the time.


I've been using autojump for 6 mos. now; it's one of my fave utilities.


Hm. Is it just me, or does it feel like describing a path with plain ol' tab completion isn't really bothersome, impractical or "a lot of keystrokes"? And since when weren't aliases good enough? I definitely see the use for this under Windows, but in a real nix shell? -shrug-


Tab completion is very painful on some of the Unix systems that I have access to. NFS can randomly hang making tab completion very unresponsive. I would have thought that, these days, this shouldn't happen. But I've experienced crapness over NFS at more than one place where I have no control over the network. As I result, I have had to resort to using fancy tools like the one posted.


I guess it all depends on the usage you make of the command line. I work with a lot of data in directories that do not have nice names (spaces, long sequences of numbers...), so autojump is very useful for me.

In any case I'd recommend to try it for a bit, I've seen quite a lot of people changing their minds after using it for a couple days. Sure, you can emulate the functionality with aliases and so on, but this is fully automatic, and after a few days, you might very well be thinking, "why didn't I use this all along?" :)


What's bothersome and impractical about describing a path with tab completion under Windows?


So, does it work on Windows, or is there a version for Windows?


It works on Cygwin.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: