Linuxメモ : Rust製のnaviでインタラクティブにチートシートを探す
navi
Rust製のnavi
はコマンドのチートシートをfzf
でインタラクティブに検索できるツール。
fzf
の使い方については下記記事を参照。
インストール
README.mdのインストール方法によるとbrew
やcargo
などでインストールできる。
$ cargo install navi
コマンドラインヘルプ。
$ navi --help navi 2.2.0 USAGE: navi [FLAGS] [OPTIONS] [SUBCOMMAND] FLAGS: -h, --help Prints help information --no-autoselect Prevents autoselection in case of single entry --no-preview Hides preview window --print Instead of executing a snippet, prints it to stdout -V, --version Prints version information OPTIONS: --fzf-overrides <fzf-overrides> FZF overrides for cheat selection (must start with an empty space) [env: NAVI_FZF_OVERRIDES=] --fzf-overrides-var <fzf-overrides-var> FZF overrides for variable selection (must start with an empty space) [env: NAVI_FZF_OVERRIDES_VAR=] -p, --path <path> List of :-separated paths containing .cheat files [env: NAVI_PATH=] -s, --save <save> [Experimental] Instead of executing a snippet, saves it to a file SUBCOMMANDS: best Autoselects the snippet that best matches the query fn Performs ad-hoc functions provided by navi help Prints this message or the help of the given subcommand(s) query Filters results repo Manages cheatsheet repositories search Uses online repositories for cheatsheets widget Shows the path for shell widget files EXAMPLES: navi # default behavior navi --print # doesn't execute the snippet navi --path '/some/dir:/other/dir' # uses custom cheats navi search docker # uses online data navi query git # filters results by "git" navi best 'sql create db' root mydb # uses a snippet as a CLI navi repo add denisidoro/cheats # imports cheats from github.com/denisidoro/cheats source <(navi widget zsh) # loads the zsh widget navi --fzf-overrides ' --with-nth 1,2' # shows only the comment and tag columns navi --fzf-overrides ' --nth 1,2' # search will consider only the first two columns navi --fzf-overrides ' --no-exact' # looser search algorithm
使い方
基本
とりあえずnavi
コマンドを実行してみる。
fzf
がインストールされていないと以下のメッセージが表示される。
fzf
がインストールされていれば以下の画面が表示されるので、まずはデフォルトのチートシートをダウンロードしてみる。
以下のように複数のチートシートが表示されるので使いそうなチートシートをTABで選択してEnterを押す(今回はgit, docker, shellを選択)。
右側には各チートシートの内容がプレビューされる。
今回試した環境では~/.local/share/navi
以下にチートシートのファイルがダウンロードされたようだ。
これでチートシートが使えるようになったのでnavi
コマンドを実行してみる。
検索したい単語を入力していくとfzf
で絞り込める。
そして、コマンド例を選択してEnterを押すとそのコマンドが実行できる(コマンドが実行されるので注意)。
以上が基本的な使い方で、その他のチートシートを追加したい場合はnavi repo browse
で探せる。
独自チートシート追加
独自チートシートを追加したい場合は、先ほどチートシートがダウンロードされた場所にファイルを作成して、
$ mkdir ~/.local/share/navi/cheats/mycheat $ touch ~/.local/share/navi/cheats/mycheat/mycheat.cheat
以下のようなフォーマットでコマンド例を記述する。
% cheat test # test command description ls -l
これで独自チートシートも検索できる。
詳細についてはREADME.mdを参照。
類似ツール
man
や--help
以外でコマンドの使い方を調べる類似ツールとしては下記がある。
- tldr
- cheat
- howdoi
- how2
- cheat.sh