2020-03-04 23:26:03 +00:00
# navi <img src="https://user-images.githubusercontent.com/3226564/65362934-b4432500-dbdf-11e9-8f75-815fbc5cbf8f.png" alt="icon" height="28px"/> [![Actions Status](https://github.com/denisidoro/navi/workflows/Quickstart/badge.svg)](https://github.com/denisidoro/navi/actions) ![GitHub release](https://img.shields.io/github/v/release/denisidoro/navi?include_prereleases)
2020-03-04 21:01:23 +00:00
2020-03-04 21:04:33 +00:00
> :information_source: This project has recently been rewritten in Rust. The old implementation was written in bash. If you're facing any issue after updating, please check [this thread](https://github.com/denisidoro/navi/issues/201).
2020-02-25 14:04:28 +00:00
2019-10-02 17:47:46 +00:00
An interactive cheatsheet tool for the command-line so that you won't say the following anymore:
2019-09-20 17:01:12 +00:00
2019-09-20 18:28:15 +00:00
>— *How to run that command again?* < br >
2019-10-03 11:47:48 +00:00
— *Oh, it's not in my shell history* < br >
2019-09-20 18:28:15 +00:00
— *Geez, it's almost what I wanted but I need to change some args*
2019-09-20 17:45:02 +00:00
2019-10-30 13:57:55 +00:00
![Demo ](https://user-images.githubusercontent.com/3226564/67864139-ebbcbf80-fb03-11e9-9abb-8e6664f77915.gif )
2019-09-20 17:01:12 +00:00
2019-10-23 21:37:51 +00:00
**navi** allows you to browse through cheatsheets (that you may write yourself or download from maintainers) and execute commands, with argument values prompted to you.
2019-09-20 17:01:12 +00:00
2019-10-02 15:13:42 +00:00
Table of contents
2019-09-22 14:52:10 +00:00
-----------------
* [Installation ](#installation )
* [Using Homebrew or Linuxbrew ](#using-homebrew-or-linuxbrew )
2020-03-04 23:08:58 +00:00
* [Downloading pre-compiled binaries ](#downloading-pre-compiled-binaries )
* [Building from source ](#building-from-source )
2019-09-22 14:52:10 +00:00
* [Upgrading ](#upgrading )
* [Usage ](#usage )
* [Preventing execution ](#preventing-execution )
* [Pre-filtering ](#pre-filtering )
* [Searching online repositories ](#searching-online-repositories )
2019-09-27 17:31:56 +00:00
* [Shell widget ](#shell-widget )
2019-09-22 14:52:10 +00:00
* [More options ](#more-options )
* [Trying out online ](#trying-out-online )
* [Motivation ](#motivation )
* [Cheatsheets ](#cheatsheets )
* [Using your own custom cheatsheets ](#using-your-own-custom-cheatsheets )
* [Submitting cheatsheets ](#submitting-cheatsheets )
* [Cheatsheet syntax ](#cheatsheet-syntax )
* [Syntax overview ](#syntax-overview )
* [Variables ](#variables )
2020-01-17 18:29:16 +00:00
* [Variable options ](#variable-options )
* [Table formatting ](#table-formatting )
* [Multiple choice ](#multiple-choice )
2019-09-26 13:50:25 +00:00
* [List customization ](#list-customization )
2019-09-22 14:52:10 +00:00
* [Related projects ](#related-projects )
* [Etymology ](#etymology )
Installation
------------
### Using Homebrew or Linuxbrew
You can use [Homebrew ](http://brew.sh/ ) or [Linuxbrew ](http://linuxbrew.sh/ )
2019-09-22 16:54:14 +00:00
to install **navi** :
```sh
2019-12-01 00:32:02 +00:00
brew install navi
2019-09-22 16:54:14 +00:00
```
2019-09-22 14:52:10 +00:00
2020-03-04 23:08:58 +00:00
### Downloading pre-compiled binaries
2019-09-22 14:52:10 +00:00
2020-03-04 23:08:58 +00:00
```bash
bash < (curl -sL https://github.com/denisidoro/navi/blob/master/scripts/install)
2019-09-30 18:18:52 +00:00
```
2020-03-04 23:08:58 +00:00
Alternatively, you can download the binaries manually [here ](https://github.com/denisidoro/navi/releases/latest ).
2019-10-12 16:45:43 +00:00
2020-03-04 23:08:58 +00:00
### Building from source
2019-10-23 16:59:15 +00:00
2020-03-04 23:08:58 +00:00
```bash
git clone https://github.com/denisidoro/navi ~/.navi
cd ~/.navi
make install
2019-10-23 16:59:15 +00:00
```
2019-09-22 14:52:10 +00:00
Usage
-----
By simply running `navi` you will be prompted with the default cheatsheets.
### Preventing execution
2019-09-26 13:50:25 +00:00
If you run `navi --print` , the selected snippet won't be executed. It will be printed to stdout instead.
2019-09-22 14:52:10 +00:00
### Pre-filtering
If you run `navi query <cmd>` , the results will be pre-filtered.
### Searching online repositories
If you run `navi search <cmd>` , **navi** will try to download cheatsheets from online repositories as well.
2019-09-26 13:50:25 +00:00
Please note that these cheatsheets aren't curated by **navi** 's maintainers and should be taken with a grain of salt. If you're not sure about executing these snippets, make sure to check the preview window or use the `--print` option.
2019-09-22 14:52:10 +00:00
2019-09-27 17:31:56 +00:00
### Shell widget
2019-10-02 17:47:46 +00:00
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.
2019-09-27 17:31:56 +00:00
2019-10-02 15:12:20 +00:00
In order to use it, add this line to your `.bashrc` -like file:
2019-09-27 17:31:56 +00:00
```sh
2019-10-02 15:12:20 +00:00
# bash
source "$(navi widget bash)"
# zsh
2019-09-27 17:31:56 +00:00
source "$(navi widget zsh)"
2019-10-14 16:44:52 +00:00
# fish
source (navi widget fish)
2019-09-27 17:31:56 +00:00
```
2019-10-02 15:12:20 +00:00
By default, `Ctrl+G` is assigned to launching **navi** . If you want to change the keybinding, replace the argument of `bind` or `bindkey` in [the widget file ](https://github.com/denisidoro/navi/search?q=filename%3Anavi.plugin.*&unscoped_q=filename%3Anavi.plugin.* ).
If you want a widget for other shells, please upvote [this issue ](https://github.com/denisidoro/navi/issues/37 ).
2019-09-27 17:31:56 +00:00
2019-09-22 14:52:10 +00:00
### More options
Please refer to `navi --help` for more details.
2019-09-20 18:28:15 +00:00
2019-09-22 14:52:10 +00:00
Trying out online
--------------------
2019-09-20 18:28:15 +00:00
2019-09-22 14:52:10 +00:00
If you don't have access to bash at the moment and you want to live preview **navi** , head to [this playground ](https://www.katacoda.com/denisidoro/scenarios/navi ). It'll start a docker container with instructions for you to install and use the tool. Note: login required.
2019-09-20 18:28:15 +00:00
2019-09-22 14:52:10 +00:00
Motivation
----------
2019-09-20 17:01:12 +00:00
The main objectives are:
2019-09-26 13:50:25 +00:00
- to increase discoverability, by finding snippets given keywords or descriptions;
2019-09-20 17:01:12 +00:00
- to prevent you from running auxiliar commands, copying the result into the clipboard and then pasting into the original command;
2019-09-20 22:20:44 +00:00
- to easily share one-liners with others so that they don't need to figure out how to write the commands;
2019-09-20 17:01:12 +00:00
- to improve terminal usage as a whole.
Sure, you can find autocompleters out there for all your favorite commands. However, they are very specific and each one may offer a different learning curve.
2019-09-20 22:16:47 +00:00
Or you can launch a browser and search for instructions on Google, but that takes some time.
2019-09-20 17:01:12 +00:00
2019-09-26 13:50:25 +00:00
**navi**, on the other hand, intends to be a general purpose platform for bookmarking any snippet at a very low cost.
2019-09-20 17:01:12 +00:00
2019-09-22 14:52:10 +00:00
Cheatsheets
-----------
2019-09-20 19:00:46 +00:00
2019-09-22 14:52:10 +00:00
### Using your own custom cheatsheets
2019-09-23 14:33:43 +00:00
In this case, you need to pass a `:` -separated list of separated directories which contain `.cheat` files:
2019-09-20 19:00:46 +00:00
```sh
2019-09-22 14:52:10 +00:00
navi --path "/folder/with/cheats"
2019-09-20 21:44:51 +00:00
```
Alternatively, you can set an environment variable in your `.bashrc` -like file:
```sh
2019-09-22 14:52:10 +00:00
export NAVI_PATH="/folder/with/cheats:/another/folder"
2019-09-20 19:00:46 +00:00
```
2019-09-22 14:52:10 +00:00
### Submitting cheatsheets
2019-09-20 22:16:47 +00:00
Feel free to fork this project and open a PR for me to include your contributions.
2019-09-22 14:52:10 +00:00
Cheatsheet syntax
-----------------
2019-09-23 14:33:43 +00:00
Cheatsheets are described in `.cheat` files.
2019-09-22 14:52:10 +00:00
### Syntax overview
2019-09-20 17:01:12 +00:00
- lines starting with `%` should contain tags which will be added to any command in a given file;
- lines starting with `#` should be descriptions of commands;
2019-09-23 14:33:43 +00:00
- lines starting with `$` should contain commands that generate a list of possible values for a given argument;
2019-09-20 17:01:12 +00:00
- all the other non-empty lines are considered as executable commands.
For example, this is a valid `.cheat` file:
```sh
% git, code
# Change branch
git checkout < branch >
2019-09-21 23:16:20 +00:00
$ branch: git branch | awk '{print $NF}'
2019-09-20 17:01:12 +00:00
```
2019-09-22 14:52:10 +00:00
### Variables
The interface prompts for variable names inside brackets (eg `<branch>` ).
2019-09-25 11:28:29 +00:00
Variable names should only include alphanumeric characters and `_` .
2019-09-22 14:52:10 +00:00
The command for generating possible inputs can refer other variables:
```sh
# If you select 2 for x, the possible values of y will be 12 and 22
echo < x > < y >
2019-09-23 14:33:43 +00:00
$ x: echo -e '1\n2\n3'
$ y: echo -e "$((x+10))\n$((x+20))"
2019-09-22 14:52:10 +00:00
```
2020-01-17 18:29:16 +00:00
### Variable options
2019-09-22 14:52:10 +00:00
2020-01-17 18:29:16 +00:00
For lines starting with `$` you can add extra options using `---` .
#### Table formatting
You can pick a specific column of a selection and set the number of lines considered as headers via `--column` and `--headers` :
2019-09-22 14:52:10 +00:00
```sh
# This will pick the 3rd column and use the first line as header
docker rmi < image_id >
2019-09-26 13:50:25 +00:00
$ image_id: docker images --- --column 3 --headers 1
2019-09-22 14:52:10 +00:00
```
2020-01-17 18:29:16 +00:00
#### Multiple choice
You can select multiple values via `--multi` and hitting `<TAB>` :
```sh
# The resulting command will be something like: cat "a.txt" "b.txt"
cat < files >
$ files: ls --- --multi true
```
2019-09-26 13:50:25 +00:00
List customization
------------------
2019-10-02 15:13:42 +00:00
Lists can be stylized with the [$FZF_DEFAULT_OPTS ](https://github.com/junegunn/fzf ) environment variable. This way, you can change the [color scheme ](https://github.com/junegunn/fzf/wiki/Color-schemes ), for example.
2019-09-26 13:50:25 +00:00
2019-10-28 19:56:19 +00:00
In addition:
- the `--fzf-overrides` option allows you to hide columns, for example
- the `--col-widths` option allows you to limit column widths
Please refer to `navi --help` for more details.
2019-09-22 14:52:10 +00:00
Related projects
----------------
2019-09-23 14:33:43 +00:00
There are many similar projects out there ([bro](https://github.com/hubsmoke/bro), [eg ](https://github.com/srsudar/eg ), [cheat.sh ](https://github.com/chubin/cheat.sh ), [tldr ](https://github.com/tldr-pages/tldr ), [cmdmenu ](https://github.com/amacfie/cmdmenu ), [cheat ](https://github.com/cheat/cheat ), [beavr ](https://github.com/denisidoro/beavr ), [how2 ](https://github.com/santinic/how2 ) and [howdoi ](https://github.com/gleitz/howdoi ), to name a few).
2019-09-20 17:01:12 +00:00
2019-09-26 13:50:25 +00:00
Most of them provide excellent cheatsheet repositories, but lack a nice UI and argument suggestions.
2019-09-20 17:01:12 +00:00
2019-09-22 15:14:33 +00:00
In any case, **navi** has the option to [search for some of these repositories ](#searching-online-repositories ).
2019-09-20 17:01:12 +00:00
2019-09-22 14:52:10 +00:00
Etymology
---------
2019-09-20 17:01:12 +00:00
In [The Legend of Zelda Ocarina of Time ](https://zelda.gamepedia.com/Ocarina_of_Time ), [navi ](https://zelda.gamepedia.com/Navi ) is a character that provides [Link ](https://zelda.gamepedia.com/Link ) with a variety of clues to help him solve puzzles and progress in his quest.