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 Tue, May 24, 2022 at 8:47 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
>
> Some lines coming from the history may be "dangerous", in the sense
> that one may not want to executed them by mistake (e.g. for lines
> recalled with a quick Ctrl-R ... [Return]).
>
> Is there some mechanism to prevent such lines from being executed if
> they were not modified after recalling them from the history?
The first question is, how do you identify those lines? Pattern match?
> something like a hook that would inspect such lines and return 0 or 1,
> depending on what one wants to do.
You can add something to zle-line-finish() that compares
[[ $BUFFER = ${history[$HISTNO]} ]]
along with whatever your other criteria are. This will always be
false for a new command line, and I believe should always be true for
an unedited line retrieved from history, but might need tweaking for
multi-line constructs.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author