Autojump
In line with my recent posts on Bash, Bash options, and other command line tools, I thought I might do a post on another CLI plugin I use regularly: autojump.
Autojump is a way to navigate the filesystem faster. It works by maintaining a database of directories you commonly cd
into. Once you’ve visited a directory, you can return to it via the autojump shortcut, saving having to type or complete the full path.
|
|
Here we change into the /foo
directory and then into our home directory. We then run the autojump convenience shortcut, j
, and return to the foo
directory.
Installing autojump
Autojump require Python 2.7+ and ships with most of the major distributions, for example on Ubuntu.
|
|
Or on OS X via Homebrew.
|
|
It supports most of the major shells, Bash, Zsh, Fish, etc and needs to be sourced by your shell before it’ll function. For Fish I would add this to my configuration.
|
|
And then source it manually or launch a new shell to automatically source it.
Using autojump
We’ve already seen autojump’s basic mode, returning to a previously visited directory. In addition to changing to a directory we can also change to a child directory of the current directory, using jc
:
|
|
We can open our default file manager in the path requested too, using the jo
shortcut.
|
|
Or to a child directory.
|
|
Autojump maintains a weighted database of directory entries, so if you have a name collision, then you can narrow it down by specifying further directory information.
j --stat
command. You can also manually add directories or change weights if needed, see j --help
for options.Let’s say you have /home/james/src/
and /home/james_work/src/
in your database like so:
|
|
Using j
autojump would leap into the higher weighted directory, /home/james/src/
, but if we want the lower weighted directory we can type:
|
|
And you’ll jet off to the lower weighted: /homes/james_work/src
.
As always, hope someone finds this useful!