navi/README.md

233 lines
8 KiB
Markdown
Raw Normal View History

2020-03-10 16:21:00 +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/Tests/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-10 16:13:32 +00:00
> :information_source: If you're here because you upgraded **navi** and are having some issues, please check [this thread](https://github.com/denisidoro/navi/issues/201).
2020-02-25 14:04:28 +00:00
2020-03-10 16:13:32 +00:00
An interactive cheatsheet tool for the command-line.
2019-09-20 17:45:02 +00:00
2020-03-11 16:01:17 +00:00
![Demo](https://user-images.githubusercontent.com/3226564/76437136-ddc35900-6397-11ea-823c-d2da7615fe60.gif)
2019-09-20 17:01:12 +00:00
2020-03-16 01:00:33 +00:00
**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.
2019-09-20 17:01:12 +00:00
2020-03-16 01:28:39 +00:00
It will:
- make you type less;
- spare you from knowing CLIs by heart;
- teach you new one-liners.
2020-03-16 01:00:33 +00:00
It uses [fzf](https://github.com/junegunn/fzf) under the hood and it can be either used as a command or as a shell widget (*à la* Ctrl-R).
2020-03-11 16:04:25 +00:00
2019-10-02 15:13:42 +00:00
Table of contents
-----------------
* [Installation](#installation)
* [Using Homebrew or Linuxbrew](#using-homebrew-or-linuxbrew)
2020-03-16 01:00:33 +00:00
* [Using cargo](#using-cargo)
* [Using install script](#using-install-script)
2020-03-04 23:08:58 +00:00
* [Downloading pre-compiled binaries](#downloading-pre-compiled-binaries)
* [Building from source](#building-from-source)
* [Usage](#usage)
2019-09-27 17:31:56 +00:00
* [Shell widget](#shell-widget)
* [More options](#more-options)
* [Trying out online](#trying-out-online)
* [Cheatsheets](#cheatsheets)
2020-03-16 01:00:33 +00:00
* [Importing cheatsheets](#importing-cheatsheets)
* [Adding your own cheatsheets](#adding-your-own-cheatsheets)
* [Submitting cheatsheets](#submitting-cheatsheets)
* [Cheatsheet syntax](#cheatsheet-syntax)
* [Syntax overview](#syntax-overview)
* [Variables](#variables)
2020-03-16 01:00:33 +00:00
* [Advanced variable options](#advanced-variable-options)
* [Variable dependency](#variable-dependency)
2020-03-16 01:00:33 +00:00
* [Multiline snippets](#multiline-snippets)
2019-09-26 13:50:25 +00:00
* [List customization](#list-customization)
* [Related projects](#related-projects)
* [Etymology](#etymology)
Installation
------------
2020-03-10 16:13:32 +00:00
### Using [Homebrew](http://brew.sh/) or [Linuxbrew](http://linuxbrew.sh/)
2020-03-11 14:32:46 +00:00
```sh
brew install denisidoro/tools/navi
```
2020-03-16 01:00:33 +00:00
Alternatively, you can use the official formula (but it will install a very old version):
2019-09-22 16:54:14 +00:00
```sh
2019-12-01 00:32:02 +00:00
brew install navi
2019-09-22 16:54:14 +00:00
```
2020-03-16 01:00:33 +00:00
### Using [cargo](https://github.com/rust-lang/cargo)
```bash
cargo install navi
```
### Using install script
2020-03-04 23:08:58 +00:00
```bash
2020-03-10 16:13:32 +00:00
bash <(curl -sL https://raw.githubusercontent.com/denisidoro/navi/master/scripts/install)
2020-03-16 01:00:33 +00:00
# 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
```
2020-03-10 16:13:32 +00:00
### Downloading pre-compiled binaries
You can download binaries [here](https://github.com/denisidoro/navi/releases/latest).
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
2020-03-16 01:00:33 +00:00
make install
# alternatively, to set install directory:
# make BIN_DIR=/usr/local/bin install
2019-10-23 16:59:15 +00:00
```
2020-03-16 01:00:33 +00:00
Usage
-----
2020-03-16 01:00:33 +00:00
By running `navi` for the first time, you'll be suggested to download some cheatsheets. By running `navi` again, these cheatsheets will appear.
2019-09-27 17:31:56 +00:00
### Shell widget
2020-03-16 01:00:33 +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. To set it up, add this line to your `.bashrc`-like file:
2019-09-27 17:31:56 +00:00
```sh
# bash
Initial cheat repo support (#258) This PR makes navi stop bundling `.cheat` files and makes it able to download from repos on GitHub, using a standardized config directory. - it fixes #233 and #237 - it makes #52, #256 and #257 much easier to implement - it makes #40 harder to implement - it's an alternate solution to #140 - it's influenced by #238 and #254. This PR ended up being much bigger than I would like so if you could review only this description it would be already very nice! When navi is started for the first time, a welcome cheatsheet is shown: ![Screenshot at 2020-03-15 10-20-04](https://user-images.githubusercontent.com/3226564/76702240-19fffd80-66a7-11ea-884f-97c565bc1ead.png) If the user selects the first option, the user is prompted to download `.cheat`s from https://github.com/denisidoro/cheats: ![Screenshot at 2020-03-15 10-20-35](https://user-images.githubusercontent.com/3226564/76702239-19fffd80-66a7-11ea-8f69-324f669b1e01.png) ![Screenshot at 2020-03-15 10-22-59](https://user-images.githubusercontent.com/3226564/76702236-18363a00-66a7-11ea-8ff4-53b497f85888.png) The config folder is populated: ![Screenshot at 2020-03-15 10-21-11](https://user-images.githubusercontent.com/3226564/76702238-19676700-66a7-11ea-8367-3e7b5733f2b4.png) When run again, cheats are available: ![Screenshot at 2020-03-15 10-21-34](https://user-images.githubusercontent.com/3226564/76702237-19676700-66a7-11ea-9c2a-d8829340f3e9.png) ### Breaking changes In order to make navi stop bundling shell widgets as well, a breaking change has been introduced: `source $(navi widget bash)` won't work anymore. It should be `source <(navi widget bash)` now. Any ideas on how to make this transition more graceful?
2020-03-15 16:46:58 +00:00
source <(navi widget bash)
# zsh
Initial cheat repo support (#258) This PR makes navi stop bundling `.cheat` files and makes it able to download from repos on GitHub, using a standardized config directory. - it fixes #233 and #237 - it makes #52, #256 and #257 much easier to implement - it makes #40 harder to implement - it's an alternate solution to #140 - it's influenced by #238 and #254. This PR ended up being much bigger than I would like so if you could review only this description it would be already very nice! When navi is started for the first time, a welcome cheatsheet is shown: ![Screenshot at 2020-03-15 10-20-04](https://user-images.githubusercontent.com/3226564/76702240-19fffd80-66a7-11ea-884f-97c565bc1ead.png) If the user selects the first option, the user is prompted to download `.cheat`s from https://github.com/denisidoro/cheats: ![Screenshot at 2020-03-15 10-20-35](https://user-images.githubusercontent.com/3226564/76702239-19fffd80-66a7-11ea-8f69-324f669b1e01.png) ![Screenshot at 2020-03-15 10-22-59](https://user-images.githubusercontent.com/3226564/76702236-18363a00-66a7-11ea-8ff4-53b497f85888.png) The config folder is populated: ![Screenshot at 2020-03-15 10-21-11](https://user-images.githubusercontent.com/3226564/76702238-19676700-66a7-11ea-8367-3e7b5733f2b4.png) When run again, cheats are available: ![Screenshot at 2020-03-15 10-21-34](https://user-images.githubusercontent.com/3226564/76702237-19676700-66a7-11ea-9c2a-d8829340f3e9.png) ### Breaking changes In order to make navi stop bundling shell widgets as well, a breaking change has been introduced: `source $(navi widget bash)` won't work anymore. It should be `source <(navi widget bash)` now. Any ideas on how to make this transition more graceful?
2020-03-15 16:46:58 +00:00
source <(navi widget zsh)
2019-10-14 16:44:52 +00:00
# fish
Initial cheat repo support (#258) This PR makes navi stop bundling `.cheat` files and makes it able to download from repos on GitHub, using a standardized config directory. - it fixes #233 and #237 - it makes #52, #256 and #257 much easier to implement - it makes #40 harder to implement - it's an alternate solution to #140 - it's influenced by #238 and #254. This PR ended up being much bigger than I would like so if you could review only this description it would be already very nice! When navi is started for the first time, a welcome cheatsheet is shown: ![Screenshot at 2020-03-15 10-20-04](https://user-images.githubusercontent.com/3226564/76702240-19fffd80-66a7-11ea-884f-97c565bc1ead.png) If the user selects the first option, the user is prompted to download `.cheat`s from https://github.com/denisidoro/cheats: ![Screenshot at 2020-03-15 10-20-35](https://user-images.githubusercontent.com/3226564/76702239-19fffd80-66a7-11ea-8f69-324f669b1e01.png) ![Screenshot at 2020-03-15 10-22-59](https://user-images.githubusercontent.com/3226564/76702236-18363a00-66a7-11ea-8ff4-53b497f85888.png) The config folder is populated: ![Screenshot at 2020-03-15 10-21-11](https://user-images.githubusercontent.com/3226564/76702238-19676700-66a7-11ea-8367-3e7b5733f2b4.png) When run again, cheats are available: ![Screenshot at 2020-03-15 10-21-34](https://user-images.githubusercontent.com/3226564/76702237-19676700-66a7-11ea-9c2a-d8829340f3e9.png) ### Breaking changes In order to make navi stop bundling shell widgets as well, a breaking change has been introduced: `source $(navi widget bash)` won't work anymore. It should be `source <(navi widget bash)` now. Any ideas on how to make this transition more graceful?
2020-03-15 16:46:58 +00:00
navi widget fish | source
2019-09-27 17:31:56 +00:00
```
2020-03-16 01:00:33 +00:00
By default, `Ctrl+G` is assigned to launching **navi**.
### More options
Please refer to `navi --help` for more details.
2019-09-20 18:28:15 +00:00
2020-03-16 01:00:33 +00:00
Trying out online
--------------------
2019-09-20 18:28:15 +00:00
2020-03-16 01:00:33 +00:00
If you don't have access to a Unix shell 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
Cheatsheets
-----------
2019-09-20 19:00:46 +00:00
2020-03-16 01:00:33 +00:00
### Importing cheatsheets
2020-03-16 01:00:33 +00:00
**navi** is able to import cheatsheets from git repositories:
2019-09-20 21:44:51 +00:00
```
2020-03-16 01:14:46 +00:00
navi repo add https://github.com/denisidoro/navi
2019-09-20 19:00:46 +00:00
```
2020-03-16 01:00:33 +00:00
### Adding your own cheatsheets
2020-03-16 01:16:16 +00:00
You can either start a git repo with cheatsheets and import it as described above or you can add them directly to [data_dir](https://github.com/soc/dirs-rs#Features)`/navi`.
2020-03-16 01:00:33 +00:00
### Submitting cheatsheets
2019-09-20 22:16:47 +00:00
2020-03-16 01:00:33 +00:00
The main repository for cheatsheets is [denisidoro/cheats](https://github.com/denisidoro/cheats). Feel free to open a PR there for me to include your contributions.
2019-09-20 22:16:47 +00:00
Cheatsheet syntax
-----------------
2020-03-16 01:00:33 +00:00
Cheatsheets are described in `.cheat` files that look like this:
2019-09-20 17:01:12 +00:00
```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
```
2020-03-16 01:00:33 +00:00
### Syntax overview
2020-03-10 16:13:32 +00:00
2020-03-16 01:00:33 +00:00
- 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
2020-03-16 01:00:33 +00:00
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 `_`.
2020-03-16 01:00:33 +00:00
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.
2020-03-16 01:00:33 +00:00
### Advanced variable options
2020-03-16 01:00:33 +00:00
For lines starting with `$` you can add use `---` to customize the behavior of `fzf` or how the value is going to be used:
```sh
# This will pick the 3rd column and use the first line as header
docker rmi <image_id>
2020-03-11 16:01:17 +00:00
$ image_id: docker images --- --column 3 --header-lines 1 --delimiter '\s\s+'
```
2020-03-16 01:00:33 +00:00
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`.
2020-03-16 01:00:33 +00:00
### Variable dependency
2020-03-16 01:00:33 +00:00
The command for generating possible inputs can refer previous variables:
```sh
2020-03-16 01:00:33 +00:00
# If you select 2 for x, the possible values of y will be 12 and 22
echo <x> <y>
2020-03-16 01:00:33 +00:00
$ x: echo '1 2 3' | tr ' ' '\n'
$ y: echo "$((x+10)) $((x+20))" | tr ' ' '\n'
```
2020-03-16 01:00:33 +00:00
### Multiline snippets
2019-09-26 13:50:25 +00:00
2020-03-16 01:00:33 +00:00
Commands may be multiline:
```sh
# This will output "foo\nyes"
echo foo
true \
&& echo yes \
|| echo no
```
2020-03-11 16:01:17 +00:00
2020-03-16 01:00:33 +00:00
List customization
------------------
2020-03-11 16:01:17 +00:00
2020-03-16 01:19:13 +00:00
Lists can be stylized with the [$FZF_DEFAULT_OPTS](https://github.com/junegunn/fzf#layout) environment variable or similar variables or parameters ( please refer to `navi --help`). This way, you can change the [color scheme](https://github.com/junegunn/fzf/wiki/Color-schemes), for example.
2020-03-11 16:01:17 +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
2020-03-16 01:00:33 +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.