No description
Find a file
2020-03-15 22:19:13 -03:00
.github Rename CI pipeline (#218) 2020-03-10 13:21:00 -03:00
scripts Vendored OpenSSL 2020-03-15 14:06:25 -03:00
shell Bump 2020-03-11 11:31:04 -03:00
src Allow repos with @ (#272) 2020-03-15 22:13:18 -03:00
tests Allow multiline commands (#262) 2020-03-14 18:08:57 -03:00
.gitignore Rust implementation (#197) 2020-03-04 18:01:23 -03:00
Cargo.lock Allow repos with @ (#272) 2020-03-15 22:13:18 -03:00
Cargo.toml Allow repos with @ (#272) 2020-03-15 22:13:18 -03:00
LICENSE Change license to Apache 2.0 (#141) 2019-10-28 16:58:19 -03:00
Makefile Allow custom dirs when running make (#214) 2020-03-09 18:41:06 -03:00
navi Add deprecation notice 2020-03-04 20:03:03 -03:00
README.md Add anchor link to FZF_DEFAULT_OPTS 2020-03-15 22:19:13 -03:00

navi icon Actions Status GitHub release

If you're here because you upgraded navi and are having some issues, please check this thread.

An interactive cheatsheet tool for the command-line.

Demo

navi allows you to browse through cheatsheets (that you may write yourself or download from maintainers) and execute commands. Argument suggestions are prompted to you.

It uses fzf under the hood and it can be either used as a command or as a shell widget (à la Ctrl-R).

Table of contents

Installation

Using Homebrew or Linuxbrew

brew install denisidoro/tools/navi

Alternatively, you can use the official formula (but it will install a very old version):

brew install navi

Using cargo

cargo install navi

Using install script

bash <(curl -sL https://raw.githubusercontent.com/denisidoro/navi/master/scripts/install)

# alternatively, to set directories:
# SOURCE_DIR=/opt/navi BIN_DIR=/usr/local/bin bash <(curl -sL https://raw.githubusercontent.com/denisidoro/navi/master/scripts/install)l

Downloading pre-compiled binaries

You can download binaries here.

Building from source

git clone https://github.com/denisidoro/navi ~/.navi
cd ~/.navi
make install 

# alternatively, to set install directory:
# make BIN_DIR=/usr/local/bin install

Usage

By running navi for the first time, you'll be suggested to download some cheatsheets. By running navi again, these cheatsheets will appear.

Shell widget

You can use navi as a widget to your shell. This way, your history is correctly populated and you can edit the command as you wish before executing it. To set it up, add this line to your .bashrc-like file:

# bash
source <(navi widget bash)

# zsh
source <(navi widget zsh)

# fish
navi widget fish | source

By default, Ctrl+G is assigned to launching navi.

More options

Please refer to navi --help for more details.

Trying out online

If you don't have access to a Unix shell at the moment and you want to live preview navi, head to this playground. It'll start a docker container with instructions for you to install and use the tool. Note: login required.

Cheatsheets

Importing cheatsheets

navi is able to import cheatsheets from git repositories:

navi repo add https://github.com/denisidoro/navi

Adding your own cheatsheets

You can either start a git repo with cheatsheets and import it as described above or you can add them directly to data_dir/navi.

Submitting cheatsheets

The main repository for cheatsheets is denisidoro/cheats. Feel free to open a PR there for me to include your contributions.

Cheatsheet syntax

Cheatsheets are described in .cheat files that look like this:

% git, code

# Change branch
git checkout <branch>

$ branch: git branch | awk '{print $NF}'

Syntax overview

  • lines starting with % determine the start of a new cheatsheet and should contain tags, useful for searching;
  • lines starting with # should be descriptions of commands;
  • lines starting with ; are ignored. You can use them for metacomments;
  • lines starting with $ should contain commands that generate a list of possible values for a given argument;
  • all the other non-empty lines are considered as executable commands.

It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with %.

Variables

The interface prompts for variable names inside brackets (eg <branch>).

Variable names should only include alphanumeric characters and _.

If there's a corresponding line starting with $ for a variable, suggestions will be displayed. Otherwise, the user will be able to type any value for it.

Advanced variable options

For lines starting with $ you can add use --- to customize the behavior of fzf or how the value is going to be used:

# This will pick the 3rd column and use the first line as header
docker rmi <image_id>

$ image_id: docker images --- --column 3 --header-lines 1 --delimiter '\s\s+'

The supported parameters are:

  • --allow-extra (experimental): handles fzf option --print-query. enter will prefer a selection and tab will prefer the query typed.
  • --multi : forwarded option to fzf.
  • --header-lines : forwarded option to fzf
  • --column : forwarded option to fzf.
  • --delimiter : forwarded option to fzf.

Variable dependency

The command for generating possible inputs can refer previous variables:

# If you select 2 for x, the possible values of y will be 12 and 22
echo <x> <y>

$ x: echo '1 2 3' | tr ' ' '\n'
$ y: echo "$((x+10)) $((x+20))" | tr ' ' '\n'

Multiline snippets

Commands may be multiline:

# This will output "foo\nyes"
echo foo
true \
   && echo yes \
   || echo no

List customization

Lists can be stylized with the $FZF_DEFAULT_OPTS environment variable or similar variables or parameters ( please refer to navi --help). This way, you can change the color scheme, for example.

There are many similar projects out there (bro, eg, cheat.sh, tldr, cmdmenu, cheat, beavr, how2 and howdoi, to name a few).

Most of them provide excellent cheatsheet repositories, but lack a nice UI and argument suggestions.

Etymology

In The Legend of Zelda Ocarina of Time, navi is a character that provides Link with a variety of clues to help him solve puzzles and progress in his quest.