Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Append cancelled commands to history



On Mar 22, 10:42am, Nadav Har'El wrote:
> Subject: Re: Append cancelled commands to history
>
> But the problem I have now is that when I now go up in the history, the
> last command I see is
> 
> 	for i in *
> 	do
> 
> which is what standard zsh saved - without the last partial line - and when I
> go up another command in history I see
> 
> 	for i in *
> 	do
> 	echo
> 
> which is what my code saved. I wished there was a way not to save that
> shorter version, with only the accepted lines.

Something like this may work:

typeset -g INTBUFFER
autoload -U add-zsh-hook

trapint_history() {
   if [[ -n "$INTBUFFER" ]]
   then
      print -s -r -- "$INTBUFFER"
      INTBUFFER=
      return 1
   fi
   return 0
}

TRAPINT() {
   zle && [[ $HISTNO -eq $HISTCMD ]] && INTBUFFER="$PREBUFFER$BUFFER"
   return $1
}

add-zsh-hook zshaddhistory trapint_history

-- 



Messages sorted by: Reverse Date, Date, Thread, Author