Claro, use a função zshaddhistory
hook e desabilite o controle regular de histórico.
function zshaddhistory() {
# defang naughty commands; the entire history entry is in $1
if [[ $1 =~ "cp\ *|mv\ *|rm\ *|cat\ *\>|pv\ *|dd\ *" ]]; then
1="# $1"
fi
# write to usual history location
print -sr -- ${1%%$'\n'}
# do not save the history line. if you have a chain of zshaddhistory
# hook functions, this may be more complicated to manage, depending
# on what those other hooks do (man zshall | less -p zshaddhistory)
return 1
}
Testado assim no zsh 5.0.8
% exec zsh
% echo good
good
% echo bad; rm /etc
bad
rm: /etc: Operation not permitted
% history | tail -4
299 exec zsh
300 echo good
301 # echo bad; rm /etc
302 history | tail -4
%
Isso parece funcionar também com o conjunto de opções extendedhistory
.