This spring I was working with a startup that wanted to use CentOS as their main development platform. Though this wasn’t my role exactly, as it is with startups, you pitch in where you can. So I also became the defacto server admin. Problem was, I am used to the Debian derivatives of Linux, so CentOS was a bit of a switch for me, especially in their default directory structure. Not a big deal, but working over a high latency connection, autocompletion wasn’t working so well. To avoid the headache of remembering new directory structure, and in general to speed up directory navigation, I decided to make a little BASH script to bookmark all the directories I commonly use on a system. Thus, HyperJump was borne.
I have used
popd as well as the autojump utility, but for my needs I wanted something else. My goals were:
- quickly jump to random directories
- persistent storage from session to session
- ability to nickname directories so the nickname does not necessarily have to be the name of the directory
- autocomplete for the nicknames
- quick and easy to use
- little to no dependencies, so it’s easy to install on any *NIX system
With that in mind I made HyperJump, a simple and quick bookmark tool for bash and zsh shells. Actually, it might work on other shells, but I only tested it on bash. A zsh patch was provided by daveFNbuck on GitHub. I tested it on OSX, Debian, CentOS, Ubuntu, and Slackware. I am sure it will run on basically anything with bash or zsh support.
In short, HyperJump is a bookmark tool and a kind of memory aid. You bookmark directories by using the
jr command (for Jump Remember), delete bookmarks with the
jf command (for Jump Forget), and jump to directories with
jjcommand (for Jump Jump, I guess). If you have Dialog utility, a UNIX CURSES utility for presenting Text Based GUI, it will also show you a list of all bookmarks, and you can select the one you would like to jump to.
HyperJump is almost pure BASH. I originally intended it to be 3 separate bash scripts, but that proved to be problematic. There is no simple mechanism by which you can change the working directory of one bash session from another one. So, when you run
jj, if it starts in a separate bash instance, it will not be able to change the working directory of the shell it was lunched from. The solution was to write the script as a function, add it to bashrc, and have it execute inside the active bash instance directly. In any case, having all 3 scripts and the supporting logic collected in one file actually turned out to be more elegant.
Download hyperjump script and place it somewhere on your system, such as
~/bin/hyperjump. Add the following line to your .profile, .bashrc or .zshrc file:
Optional: To get the list of all the Bookmarks in a nice looking menu window, you need a unix utility called dialog. You can install it via yum, apt-get, homebrew, ports, and others like so:
# On CentOS or Another RedHat Derivative sudo yum install dialog # On Ubuntu or Another Debian Derivative sudo apt-get install dialog # On OS X brew install dialog sudo port install dialog
HyperJump consists of 3 command line commands (functions).
- jr – Remember Jump. Bookmarks current directory. Run
jr nicknameto add current directory, or just run
jrand use the interactive mode.
- jf – Forget Jump. Deletes the current directory from the bookmarks. Run
jfwhile in a directory you want forgotten or
jf nicknameto forget a specific nickname.
- jj – Jump to a bookmark location. Run
jj nicknameto jump to a location or just
jjto get a list of all bookmarks. You can also run
jj nickname commandto jump to a location and than run the command specified with “./” as the first argument. So, for instance, you can run
jj myProject open sublon OSX to jump to the myProject directory and open the myProject directory in Finder and Sublime Text.
All of the commands have autocomplete. Both jj and jf will autocomplete with nicknames of bookmarked locations. The jr command will autocomplete with the basename of the current directory. After the first argument, jj will autocomplete with list of available system commands (programs).
# Remember current directory jr jr MyDir # Forget current directory jf # Forget another directory jf AnotherDir # Jump to a Directory jj jj MyDir # Jump to a directory and open the directory in another program(s) jj MyDir open jj MyDir open subl tm