From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-users@zsh.org
Subject: Re: prevent some lines directly coming from the history from being executed
Date: Wed, 25 May 2022 04:54:03 +0200 [thread overview]
Message-ID: <20220525025403.GA97860@zira.vinc17.org> (raw)
In-Reply-To: <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@vinc17.net> 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@vinc17.net> - 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)
next prev parent reply other threads:[~2022-05-25 2:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-24 15:47 Vincent Lefevre
2022-05-24 18:58 ` Bart Schaefer
2022-05-25 2:54 ` Vincent Lefevre [this message]
2022-05-25 3:59 ` Bart Schaefer
2022-05-25 8:49 ` Vincent Lefevre
2022-05-26 1:25 ` Bart Schaefer
2022-05-26 14:36 ` Vincent Lefevre
2022-05-26 15:53 ` Daniel Shahaf
2022-05-26 16:13 ` Peter Stephenson
2022-05-27 12:40 ` Daniel Shahaf
2022-05-28 0:07 ` Vincent Lefevre
2022-05-28 10:06 ` Daniel Shahaf
2022-05-28 18:43 ` Bart Schaefer
2022-05-29 22:55 ` Daniel Shahaf
2022-05-30 4:04 ` Bart Schaefer
2022-05-30 9:07 ` Peter Stephenson
2022-06-02 9:59 ` Daniel Shahaf
2022-06-02 10:19 ` Daniel Shahaf
2022-06-02 9:59 ` Daniel Shahaf
2022-05-30 9:02 ` Vincent Lefevre
2022-06-02 10:17 ` Daniel Shahaf
2022-06-02 13:54 ` Vincent Lefevre
2022-05-26 16:37 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220525025403.GA97860@zira.vinc17.org \
--to=vincent@vinc17.net \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).