Quick refactor

Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com>
This commit is contained in:
alexis-opolka 2025-03-24 01:54:22 +01:00
parent d5f1664213
commit fbf4c0165b
5 changed files with 40 additions and 129 deletions

View file

@ -1,6 +0,0 @@
% first cheat
# print something
echo "My name is <name>!"
$ name: whoami

View file

@ -1,44 +0,0 @@
% cheatsheets
# Download default cheatsheets
navi repo add denisidoro/cheats
# Browse for cheatsheet repos
navi repo browse
# Edit main local cheatsheets
f="$(navi info cheats-path)/main.cheat"
[ -f "$f" ] || navi info cheats-example > "$f"
${EDITOR:-nano} "$f"
% config
# Edit config file
f="$(navi info config-path)"
[ -f "$f" ] || navi info config-example > "$f"
${EDITOR:-nano} "$f"
% 3rd-party
# Search using tldr
navi --tldr "<query>"
# Search using cheatsh
navi --cheatsh "<query>"
% widget
# Load shell widget
shell="$(basename $SHELL)"; eval "$(navi widget $shell)"
% help
# Read command-line help text
navi --help
# Read project README.md
navi fn url::open "https://github.com/denisidoro/navi"

View file

@ -1,39 +0,0 @@
# THIS IS EXPERIMENTAL
# the config file schema may change at any time
style:
tag:
color: cyan # text color. possible values: https://bit.ly/3gloNNI
width_percentage: 26 # column width relative to the terminal window
min_width: 20 # minimum column width as number of characters
comment:
color: blue
width_percentage: 42
min_width: 45
snippet:
color: white
finder:
command: fzf # equivalent to the --finder option
# overrides: --tac # equivalent to the --fzf-overrides option
# overrides_var: --tac # equivalent to the --fzf-overrides-var option
# delimiter_var: \s\s+ # equivalent to the --delimiter option that is used with --column option when you extract a column from the selected result for a variable
# cheats:
# paths:
# - /path/to/some/dir # on unix-like os
# - F:\\path\\to\\dir # on Windows
# path: /path/to/some/dir # (DEPRECATED) equivalent to the --path option
# search:
# tags: git,!checkout # equivalent to the --tag-rules option
# client:
# tealdeer: true # enables tealdeer support for navi --tldr
shell:
# Shell used for shell out. Possible values: bash, zsh, dash, ...
# For Windows, use `cmd.exe` instead.
command: bash
# finder_command: bash # similar, but for fzf's internals

View file

@ -1,40 +1,40 @@
## Using it for shell scripting
For a real world scenario example, please check this [blog post](https://denisidoro.github.io/posts/cli-templates/).
Let's say you want to write a bash script that, among other things, asks the user to write the name of a git branch that should be checked out.
If you already have the [cheatsheet above](#cheatsheet-syntax), then you could write the following in your script:
```sh
navi --query "change branch" --best-match
```
**navi** will ask the user to fill all arguments needed.
If you want to set the `<branch>` beforehand in your script:
```sh
branch="master" navi --query "change branch" --best-match
```
- no interactive input will be shown
- the value for `<branch>` will be exactly the one passed as argument
If you want to filter some results for `<branch>`:
```sh
branch__query="master" navi --query "change branch" --best-match
```
- an interactive input will be shown, unless a single entry is autoselected
- the value for `<branch>` will be the one selected
If you want to select the best match for `<branch>`:
```sh
branch__best="master" navi --query "change branch" --best-match
```
- no interactive input will be shown
- the value for `<branch>` will be the one that best matches the one passed as argument
## Using it for shell scripting
For a real world scenario example, please check this [blog post](https://denisidoro.github.io/posts/cli-templates/).
Let's say you want to write a bash script that, among other things, asks the user to write the name of a git branch that should be checked out.
If you already have the [cheatsheet above](#cheatsheet-syntax), then you could write the following in your script:
```sh
navi --query "change branch" --best-match
```
**navi** will ask the user to fill all arguments needed.
If you want to set the `<branch>` beforehand in your script:
```sh
branch="master" navi --query "change branch" --best-match
```
- no interactive input will be shown
- the value for `<branch>` will be exactly the one passed as argument
If you want to filter some results for `<branch>`:
```sh
branch__query="master" navi --query "change branch" --best-match
```
- an interactive input will be shown, unless a single entry is autoselected
- the value for `<branch>` will be the one selected
If you want to select the best match for `<branch>`:
```sh
branch__best="master" navi --query "change branch" --best-match
```
- no interactive input will be shown
- the value for `<branch>` will be the one that best matches the one passed as argument