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

Re: Append cancelled commands to history



On Mar 24, 12:27pm, Nadav Har'El wrote:
}
} Anyway, I tried what you wrote, and it didn't work because it appears the
} zshaddhistory hook does not get called when I interrupt the ZLE.

Ah.  That makes sense.  I was assuming it didn't work for me because
of the $PREBUFFER-is-empty problem (for which a patch has since been
posted on zsh-workers).

} So apparently, that interrupted multiline editing is *not* in the
} history, and never was. So where is it? Why do I see it when I go "up"
} for the first time? How do I prevent this?

Oh, of course.  Zsh *always* makes the immediately preceding accepted
input available for scrollback in the line editor, even if it was not
put into the history (because of HIST_IGNORE_ALL_DUPS, HIST_NO_STORE,
or HIST_IGNORE_SPACE, etc.).

There is no way to prevent this.

You could, however, stop using the interrupt signal and its trap, and
instead re-bind ctrl-C (or whatever your interrupt key is) to a zle
function that, whenever $PREBUFER is non-empty, does a no-op equivalent
of accept-line followed by a send-break.

    typeset -gi INTR_PRESSED=0

    finish_simulated_interrupt() {
      if (( INTR_PRESSED ))
      then
	INTR_PRESSED=0
	return 1
      else
	return 0
      fi
    }
    add-zsh-hook preexec finish_simulated_interrupt

    simulate-interrupt() {
      if [[ -n $PREBUFFER ]]
      then
	INTR_PRESSED=1
	zle -U $'\a'	# Replace with your send-break keystroke
	zle accept-line
      else
	zle send-break
      fi
    }
    zle -N simulate-interrupt

Rebinding keys to call simulate-interrupt instead of sending a real
terminal driver interrupt, is left as an exercise.

-- 



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