Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: prevent some lines directly coming from the history from being executed
- X-seq: zsh-users 27798
- From: Vincent Lefevre <vincent@xxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: prevent some lines directly coming from the history from being executed
- Date: Wed, 25 May 2022 04:54:03 +0200
- Archived-at: <https://zsh.org/users/27798>
- In-reply-to: <CAH+w=7ZXO12Gb7LFGT0US=M=xBdi1XHoMU7t7n4=cbov+EKcNA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- References: <20220524154738.GA35284@cventin.lip.ens-lyon.fr> <CAH+w=7ZXO12Gb7LFGT0US=M=xBdi1XHoMU7t7n4=cbov+EKcNA@mail.gmail.com>
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?
Yes.
> > 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