I'm using snippet code below to exclude all failed commands (return code 1) from saving to zsh history:
zshaddhistory() { whence ${${(z)1}[1]} >| /dev/null || return 1 }
But if the command is an alias lsl
(alias lsl='ls -l') the failed command will still be inserted into zsh history:
lsl whatever_folder_doesnt_exist
whatever_folder_doesnt_exist
doesn't exist and I observe lsl whatever_folder_doesnt_exist
still in zsh history.
Here I want to exclude all command that return code is not 0
, how can I do that?
precmd
that checks the return code and "manually" edits the history file to remove failed commands? – Jeff Schaller May 25 '20 at 01:10