I'm using snippet code below to exclude all failed commands (return code 1) from saving to zsh history:
zshaddhistory() { whence ${${(z)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?
Asked by raring-coffee20
(1855 rep)
May 6, 2020, 07:54 AM
Last activity: Jun 11, 2025, 09:56 AM
Last activity: Jun 11, 2025, 09:56 AM