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 11:58:04 -0700, Bart Schaefer wrote:
> 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.

This doesn't seem to work. I've added

  [[ $BUFFER = ${history[$HISTNO]} ]]

at the end (thus currently catching all unmodified lines), but
this doesn't change anything. Is the exit status of the function
really taken into account to prevent the execution?

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