Bugzilla – Bug 1216391
zsh precmd breaks history
Last modified: 2023-12-09 21:38:20 UTC
The below as either .zshrc or .bashrc inserts a header at the top of the history of every shell session. in bash it's silent on standard out as desired and the header inserts before the first command of each session. in zsh the header appears both on standard out and in the history *after* the first command of the session. Changing "preexec" to "precmd" seems like it ought to put the header before the first command of the session. But instead it breaks history, nothing appears in history. Looks like a bug.. HISTTIMEFORMAT="%F%a%T " if [ $ZSH_NAME ] then emulate -R sh #whether or not history breaks is consistent whether both, setopt extendedhistory #either, or neither of the emulate&setopt commands are included else shopt -s histappend fi HIShead(){ echo ===header $WINDOW $SUDO_USER;} HISTwin(){ [[ $WINDo = $WINDOW ]]||{ WINDo=$WINDOW;HISneww;};} if [ $ZSH_NAME ] then #precmd(){ HISTwin;} #breaks history preexec(){ HISTwin;} #inserts header after not before first command HISneww(){ fc -eHISplic;} HISplic(){ echo \#$(HIShead)>|$1;} #zsh, insert a header whenever WINDOW is new else HISneww(){ history -s $(HIShead);} #bash, same PROMPT_COMMAND=HISTwin fi
well the above still looks like a bug, but meanwhile what i really wanted turns out to be "print -s", and this doesnt break history: HISTTIMEFORMAT="%F%a%T " if [ $ZSH_NAME ] then emulate -R sh setopt extendedhistory else shopt -s histappend fi hshead(){ $HS ===header $WINDOW $SUDO_USER;} precmd(){ [[ $WINDo = $WINDOW ]]||{ WINDo=$WINDOW;hshead;};} #new window? if [ $ZSH_NAME ] then HS=print\ -s else HS=history\ -s fi