Closed martin-braun closed 1 year ago
That's already possible in Zsh natively. You have three options for this, all of which can be combined:
setopt HIST_IGNORE_SPACE
to your .zshrc
file. Then, if you insert at least one space at the very beginning of a command line, it will not be saved to history, although it is still saved to local history in memory.HISTORY_IGNORE=<glob pattern
to your .zshrc
file. Then, any command line that matches that pattern will not be saved to history..zshrc
file:
autoload -Uz
<function>() {
<logic>
}
add-zsh-hook zshaddhistory <function>
Then, whenever you submit a command line, before it is executed, it will be passed to this function. If the function returns 1
, it will not be saved. If it returns 2
, it will be saved to local history in memory, but will not be saved to the $HISTFILE
. Returning 0
will save the command line to history, unless prevented by one of the other two options.
@marlonrichert Thank you for the detailed explanation, it makes sense to do it this way. Very useful.
What do you want?
Running a command without it being added to the history in the first place (sort of, it shall be added, but removed instantly). This would be great, as it would allow to send a single command in incognito without the necessity to send a
hist d -1
afterwards.Why do you want this?
I have so send a secret to my Android phone via USB debugging (
adb shell -n input text
), because the TAN2GO app of my bank won't allow me to paste in passwords from my password manager. Flawed design. I then want to prevent the secret in my history.Who else would benefit from this?
Anybody who wants to send a single command and delete it from history in one go, i.e. when having the command on the password manager like I do. Right now, sending
adb shell -n input text mysecret; hist d -1
will not remove the secret, but the history entry prior. So the user has to send two commands.How should it work?
Given this situation: A new flag to secretly send a command and remove it from history afterwards, let's call it
ignore
/i
?When I perform these steps:
hist ignore echo secret
Then I expect this to happen: It should print
secret
without addingecho secret
to the history.Thanks!