denisidoro / navi

An interactive cheatsheet tool for the command-line
Apache License 2.0
14.63k stars 491 forks source link

Support non-interactive mode #808

Open slayer152 opened 1 year ago

slayer152 commented 1 year ago

Is your feature request related to a problem? Please describe. I want to be able to grab a snippet corresponding to a query without interaction, for e.g. to pass it verbatim to a colleague or to check if a snippet already exists. Using --best-match and --print still needs interaction when the snippet has variables. Please see "Additional context" for more details and use-cases. I understand this might be a niche request but TIA for your consideration.

Describe the solution you'd like 1) Add a subcommand or an option to print all queries (perhaps filterable by tags) without interaction. 2) Add a sub-command or an option to print out the snippet verbatim / raw format (the variable references can remain) for a given query.

Describe alternatives you've considered I'm currently using grep+sed in a wrapper script to get one and two but it feels a little hacky/brittle

# get a list of all queries without interaction
grep -hroP "^\s*#\s*\K.*" "$(navi info cheats-path)"
# get snippet matching query 'Force clean none/dangling images' without interaction
find -L "$(navi info cheats-path)" -type f -print0 | xargs -r0 sed -E -n "/^[ ]*#[ ]*Force clean none\/dangling images[ ]*$/, /^[ ]*$/{ /^[ ]*#[ ]*Force clean none\/dangling images[ ]*$/! { /^[ ]*$/! p } }"

Additional context A couple of use-cases where such a feature would be helpful (atleast for me) are: 1) Colleague doesn't have/want to have navi but asks "how do i do xyz". I'd like to run navi locally and give them the snippet and say "replace things between < and > as needed". In the current interactive form, navi asks for user-input for the variables which can be pre-populated only with info from my machine and colleague's machine may have different data for the variables.

2) I want to add a cheat but I'm not sure if it's already there. I just want to invoke navi to tell me whether such a snippet already exists without interaction.

3) Emacs supports two shells out of the box, the inferior shell (shell-mode) and eshell which have their own advantages over its built-in and 3rd party terminal emulator packages. The shells don't support interactive programs like navi and a non-interactive invocation of navi will be helpful to atleast dump the snippet verbatim.

welcome[bot] commented 1 year ago

Thanks for opening your first issue here! In case you're facing a bug, please update navi to the latest version first. Maybe the bug is already solved! :)