navi

navi is a cheat sheet tool for the command line. It allows looking up common commands by your description, chaining multiple commands together, and building arguments for those commands.

Writing Cheatsheets

Start the cheat cheat sheet with a % followed by tags, for example:

% git, command_line

Add a new command with a note (prefixed by #):

# switch branches
git checkout

Trying it out: Assuming navi is setup correctly and you are loading this new cheat sheet. You can try this out by going to the terminal and hitting CTRL+G this will show all of your “cheats”. Type what you are looking for (it will fuzzy match) e.g. ‘branch’, hit enter on our newly created cheat and you will see the command populated at your prompt, you could then type a branch name and hit enter.

$ # hit control g, find my cheat and hit enter
$ git checkout # type the name of my branch and hit enter

But that isn’t that useful, what if we could prompt for a branch name? We can by adding a variable into the cheat

# switch branches
git checkout <branch>

Save and repeat your testing process, notice that now it asks you for the branch before interpolating the command at your prompt.

$ # hit control g, find my cheat and hit enter. Get prompted for a branch name, type "Other-Branch", hit enter
$ git checkout Other-Branch

That’s handy, but not much more efficient than the first example. What if we could select from a list of our local branches? We can by populating the variables with a list, navi provides a syntax for that which looks like:

$ <VARIABLE_NAME>: <COMMAND_TO_POPULATE_VARIABLE>

So modifying our cheatsheet again:

# switch branches
git checkout <branch>

$ branch: git branch | grep -v '*' | cut -c 3-

note: cut is used here to trim the white space from the front of the branch names

Repeating our test, we can now hit CTRL+G find out cheat, be prompted for other local branches and then automatically fill in the command we want. Neat!

Links to this note