4 releases (breaking)
0.5.1 | Jan 2, 2023 |
---|---|
0.4.0 | Jul 27, 2019 |
0.3.1 | Dec 10, 2017 |
0.2.1 | Dec 13, 2016 |
#599 in Filesystem
48KB
1K
SLoC
autojump-rs
A port of the wildly popular helper application autojump
to Rust.
License
As this project is technically a fork, the license is the same as autojump
,
which is GPL, either version 3 or any later version. See LICENSE
for details.
Install
We have prebuilt binaries available for a while now, thanks to the trust project!
The package is a drop-in replacement of autojump
. Assuming autojump
is
already installed, or at least the shell script part of it has been properly
set up, and you have in $PATH
~/.cargo/bin
before the system binary
locations, all you have to do is to put a binary of your choice architecture
in your PATH, overriding the original autojump
script.
You may have to issue hash -r
for the shell to forget previous
location of autojump
, if you don't want to re-exec your shell.
(Manually cloning the repository and building is okay, of course.)
Features
Why do a port when the original version works? Primarily for two reasons:
- The author is really tired of
autojump
breakage inside Python virtualenvs, and - Rust is simply awesome for CLI applications, with its performance and (code) slickness!
Indeed, being written in a compiled language, autojump-rs
is very light on
modern hardware. As the program itself is very short-running, the overhead of
setting up and tearing down a whole Python VM could be overwhelming,
especially on less capable hardware. With autojump-rs
this latency is
greatly reduced. Typical running time is like this on the author's Core
i7-2670QM laptop, with a directory database of 1014 entries:
$ time ./autojump/bin/autojump au
/home/xenon/src/autojump-rs
./autojump/bin/autojump au 0.09s user 0.01s system 99% cpu 0.103 total
$ time ./autojump-rs/target/release/autojump au
/home/xenon/src/autojump-rs
./autojump-rs/target/release/autojump au 0.00s user 0.00s system 87% cpu 0.007 total
The time savings are more pronounced on less powerful hardware, where every cycle shaved off counts. The running time on a 1.4GHz Loongson 3A3000 is about 10ms, for example, which is very close to the x86 figures despite the clock frequency difference.
And, of course, the program no longer interacts with Python in any way, so the
virtualenv-related crashes are no more. Say goodbye to the dreaded
ImportError
's showing every $PS1
in a virtualenv with the system-default
Python!
# bye and you won't be missed!
Traceback (most recent call last):
File "/usr/lib/python-exec/python2.7/autojump", line 43, in <module>
from autojump_data import dictify
ImportError: No module named autojump_data
Compatibility
All of the command line flags and arguments are now implemented, and behave
exactly like the original. Being a drop-in replacement, all other shell
features like tab completion should work too. (Except jc
and jco
; see
below.)
As for the text database, the on-disk format should be identical. (Actually there is a little difference in the representation of floats, but it doesn't matter.) However, as the author is developing and using this on Linux, other platforms may need a little more love, although all the libraries used are lovingly cross-platform. (Patches are welcome, of course!)
The Windows batch files shipped with the original autojump
has Python
hard-coded into them, and obviously that won't work with autojump-rs
.
Use the batch files in the windows
directory instead; just replacing the
original files and putting autojump.exe
along with them should work.
(Thanks @tomv564 for the Windows testing!)
That said, there're some IMO very minor deviations from the original Python implementation. These are:
-
Argument handling and help messages.
Original
autojump
uses Python'sargparse
to parse its arguments. There is a Rust port of it, but it's nowhere as popular as thedocopt.rs
library, as is shown incrates.io
statistics and GitHub activities. So it's necessary to re-arrange the help messages at least, as thedocopt
family of argument parsers mandate a specific style for them. However this shouldn't be any problem, just that it's different. Again, who looks at the usage screen all the day? XD -
Different algorithm chosen for fuzzy matching.
The Python version uses the
difflib.SequenceMatcher
algorithm for its fuzzy matches. Since it's quite a bit of complexity, I chose to leverage thestrsim
library instead. The Jaro-Winkler distance is computed between every filename and the last part of query needles respectively, and results are filtered based on that. -
jc
may jump outside current directory.Exact reason may be different filtering logic involved, but I'm not very sure about this one. The behavior is also observed on original
autojump
, but the frequency seems to be lower, and both implementations actually don't check if the target is below current directory. However I only use plainj
mostly, so if you're heavily reliant onjc
and its friends please open an issue!
Future plans
Now that platform support is mostly considered okay, next steps would be
more refactoring and bug fixing. The jc
behavior differences are observed
on original autojump
too, in that you could jump outside $(pwd)
, but the
actual directory jumped to is different; this needs further investigation.
Hell I even want to write a fasd
backend too, but I don't presently have
that much free time. Anyway, contributions and bug reports are welcome!
Dependencies
~5–15MB
~208K SLoC