Bug 1216391 - zsh precmd breaks history
Summary: zsh precmd breaks history
Status: NEW
Alias: None
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Other (show other bugs)
Version: Current
Hardware: x86-64 openSUSE Tumbleweed
: P5 - None : Normal (vote)
Target Milestone: ---
Assignee: Paolo Perego
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 1217304
  Show dependency treegraph
 
Reported: 2023-10-18 20:30 UTC by greg mott
Modified: 2023-12-09 21:38 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description greg mott 2023-10-18 20:30:31 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
Comment 1 greg mott 2023-12-09 21:38:20 UTC
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