2024-11-27
navi is an interactive cheatsheet tool for the command-line. Though it is described as a cheatsheet officially, I found it is more suitable as a launcher. I want to share my use of it.
Let’s describe what navi
is. When typing navi
, it will show a list
of commands, and users can select it by fuzzy searhcing and then invoke
it. Additionally, it supports features to define variables during
launching and else. So you can build commands step by step dynamically.
However, for me, the most powerful feature is that it allows you edit commands before executing. Extra steps are required to enable this feature:
# bash
eval "$(navi widget bash)"
# zsh
eval "$(navi widget zsh)"
# fish
navi widget fish | source
After setup, when pressing Ctrl + G, fzf
will be
toggled and users can select a command. After pressing Enter,
the command will populate into the shell.
With this feature, I can use it as an alternative to Postman. I only
need to create a cheatsheet like
"$(navi info cheats-path)/dummy-api.cheat"
as below.
% dummy api
# edit dummy api cheatsheet
"$EDITOR" "$(navi info cheats-path)/dummy-api.cheat"
# create a product
curl -X POST http://localhost:1111/api/products \
-d '
{
"name": "dummy",
"sku": "SKU"
}
'
# read a product
curl -X GET http://localhost:1111/api/products/dummy-id
Then I can use Ctrl + G to swiftly generate curl
scripts by the templates I defined before, and test APIs under
development quickly.