Shell addon
At our last PYPTUG meeting, I was demoing Dshell. While at it I suggested using the j command. AKA, autojump:
https://github.com/joelthelion/autojump
On some linux distros, it is possible to install from the repo. On debian and derived systems (ie, ubuntu, mint etc), instructions to enable it after the install are in /usr/share/doc/autojump/README.Debian
Once installed and trained, you'll ask yourself how you've been able to live without it.
The j command itself is defined within a shell file. For example, for bash, you'll find this piece of code:
# default autojump command | |
j() { | |
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then | |
autojump ${@} | |
return | |
fi | |
output="$(autojump ${@})" | |
if [[ -d "${output}" ]]; then | |
echo -e "\\033[31m${output}\\033[0m" | |
cd "${output}" | |
else | |
echo "autojump: directory '${@}' not found" | |
echo "\n${output}\n" | |
echo "Try \`autojump --help\` for more information." | |
false | |
fi | |
} | |
Although this part is all bash scripting, the actual autojump command is written in something else altogether.
Python powered
Autojump has been around for many years, to this day, few people actually are aware of it. In fact, as I typed j, a quick survey around the room confirmed my gut feel.
Python powered
I have blogged and tweeted about it before, but mostly in passing. Hopefully this post will bring a bit more exposure to this really useful tool.
And, do have a look at the python code ( https://github.com/joelthelion/autojump/blob/master/bin/autojump ). It has some interesting use of the lesser known SequenceMatcher class of the difflib module, and good use of lambdas. Oh, and yeah, it's pep8 formatted. Thank you.
Francois
@f_dion
No comments:
Post a Comment