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

Re: prevent some lines directly coming from the history from being executed



On 2022-05-24 20:59:53 -0700, Bart Schaefer wrote:
> zle-line-finish() {
>   if [[ $BUFFER = ${history[$HISTNO]} ]]; then
>     local confirm
>     read -q confirm"?Confirm: $BUFFER ?"
>     [[ $confirm = y ]] || BUFFER=""
>   fi
> }

There are some display issues in some cases due to the "Confirm"...
Instead, if the condition is met, is it possible to remain in ZLE
with the current buffer, as if I didn't do accept-line?
(I could set a psvar element so that I could change the prompt to
indicate that this needs confirmation.)

Or perhaps I could change the bindings to use a wrapper around
accept-line (ditto for accept-line-and-down-history).

Something like that (to be completed with pattern matching):

zle -A accept-line real-accept-line

accept-line-wrapper() {
  if [[ -z $psvar[3] && $BUFFER = ${history[$HISTNO]} ]]; then
    psvar[3]="[Confirm]"
    zle reset-prompt
  else
    psvar[3]=""
    zle real-accept-line
  fi
}

zle -N accept-line accept-line-wrapper

where $PS1 contains "%3v", and with psvar[3]="" in precmd().

Could there be any issue? Or is there anything to add?

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




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