feat: add --print-command and --print-cheat flags#1011
Conversation
alexis-opolka
left a comment
There was a problem hiding this comment.
Before doing any actual review on the code, I would like to have the thoughts of @denisidoro and @kit494way with which we've had some discussions about it during different PRs.
This feature has been requested multiple times, for a raw navi call to behave the same way it behaves when used with a shell plugin. In the way that you have an entry of the resolved command in the shell history.
It's also worth mentioning that these kinds of features can also have safety impacts, which were in part discussed in #977, then in #981 and is currently tracked with the feat/variable-history branch where variables could be exposed in the shell history as raw values, which is clearly not recommended.
@kavau have you tried to see if your modifications were impacted with the use of a shell plugin?
In the case the print command is activated, for example. I'm just blindly asking here.😅
| pub print: bool, | ||
|
|
||
| /// Prints the command to stdout before executing it | ||
| #[arg(short = 'P', long)] |
There was a problem hiding this comment.
I'd rather not add the short option, because we'll need to maintain it forever (unless there's a breaking change).
| pub print_command: bool, | ||
|
|
||
| /// Prints the full cheat (comment + command) before executing it | ||
| #[arg(short = 'C', long)] |
| #[cfg(not(feature = "disable-command-execution"))] | ||
| pub print: bool, | ||
|
|
||
| /// Prints the command to stdout before executing it |
There was a problem hiding this comment.
Could you please consider making it print to stderr instead?
This way it won't break commands like navi --print-command -q 'command which echoes to stdout' | grep 'foo'.
By printing to stderr, you can still break commands which read from stderr, but that's much more rare.
@alexis-opolka I'm afraid I don't understand the concern around shell plugins. Could you please elaborate? |
|
Of course ^^ I might be completely wrong on that, I'm talking about it from some time ago so don't hesitate to correct me if I'm wrong. 😅 There were some concerns about how a command is stored within a shell history when resolving commands and/or variables, in the way that when you type the actual command within a shell (or use the plugins for navi), the actual value of the variable is not recorded in the shell history. The other one is not an actual concern and more of a question on how printing the resolved command would behave when using a shell plugin. Which would be more impacted if the values are actually part of the configuration, as requested by #1009 . I don't know if I was clear enough, as I said I might be completely wrong about that. 😅 P.S. The shell plugin would need to call navi with the explicit flags though to actually see the behaviour but it never hurts to ask. ^^ |
|
Wouldn't a shell function be enough for the function navi-print-command
set cmd (navi --print)
echo "navi> $cmd"
echo "$cmd" | fish
endPrinting a description of a cheat is not mentioned in the relevant issue (#1009). IMO, it is better for navi to focus on parsing cheats, launching a fuzzy finder like fzf and outputting the necessary information. |
Summary
This PR adds two new optional flags that print information about the selected
cheat to stdout before executing it.
--print-command/-PPrints the resolved command before executing it:
Useful for keeping a visible record of what was run in a terminal session.
--print-cheat/-CPrints a formatted block with the comment and command before executing it:
The separator width adapts to the longest line (capped at 80 chars). The
comment and command are coloured using
crossterm(already a dependency).Motivation
Selecting a cheat, having navi execute it, and then seeing only the command output but not the command itself, feels like "flying blind". It's nicer and safer to have a record of exactly what happened in the terminal output.
Changes
src/config/cli.rs— new--print-command(-P) and--print-cheat(-C) flags, plus examples in--helpsrc/config/mod.rs—print_command()andprint_cheat()accessors onConfigsrc/commands/core/actor.rs— print logic beforespawn()docs/usage/README.md— new sections documenting--print-commandand--print-cheatNotes
rust-toolchain.tomlwas bumped from1.81.0to1.88.0to resolve abuild failure caused by transitive dependencies requiring newer editions
(
getrandom 0.4,home 0.5.12). This seems like a pre-existing issueworth fixing regardless of this PR.
-Cand-Pare passed,-Ctakes precedence.MAINTAINER EDIT: Partially answers to #1009