* widget accept-no-history
@ 2023-08-23 14:40 Pier Paolo Grassi
2023-08-24 3:20 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Pier Paolo Grassi @ 2023-08-23 14:40 UTC (permalink / raw)
To: Zsh-Users List
[-- Attachment #1: Type: text/plain, Size: 521 bytes --]
Years ago I created a widget that allows me to accept a line without
committing it to the history:
execute_no_history(){
fc -p /dev/null
________tmp___restore_history=1
zle accept-line
}
and my precmd contains:
precmd(){
[[ $________tmp___restore_history -eq 1 ]] && {
unset ________tmp___restore_history
fc -P
}
}
now I noticed that when I execute it as a non-privileged user, I get:
precmd:3: locking failed for /dev/null: permission denied
So I wonder, what would be a better implementation?
Pier Paolo Grassi
[-- Attachment #2: Type: text/html, Size: 956 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: widget accept-no-history
2023-08-23 14:40 widget accept-no-history Pier Paolo Grassi
@ 2023-08-24 3:20 ` Bart Schaefer
2023-08-24 14:01 ` Pier Paolo Grassi
0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2023-08-24 3:20 UTC (permalink / raw)
To: Pier Paolo Grassi; +Cc: Zsh-Users List
On Wed, Aug 23, 2023 at 7:41 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> Years ago I created a widget that allows me to accept a line without committing it to the history:
[...]
> So I wonder, what would be a better implementation?
How about something along the lines of:
execute_no_history() {
setopt hist_ignore_space
zle .accept-line
}
zshaddhistory() {
[[ -o hist_ignore_space ]] && return 2
}
precmd() {
unsetopt hist_ignore_space
}
You can use a global variable instead of any otherwise-unused setopt
if you prefer.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: widget accept-no-history
2023-08-24 3:20 ` Bart Schaefer
@ 2023-08-24 14:01 ` Pier Paolo Grassi
2023-08-24 17:47 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Pier Paolo Grassi @ 2023-08-24 14:01 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh-Users List
[-- Attachment #1: Type: text/plain, Size: 802 bytes --]
I see, I wasn't aware of the zshaddhistory hook
thanks Bart
Pier Paolo Grassi
Il giorno gio 24 ago 2023 alle ore 05:20 Bart Schaefer <
schaefer@brasslantern.com> ha scritto:
> On Wed, Aug 23, 2023 at 7:41 AM Pier Paolo Grassi <pierpaolog@gmail.com>
> wrote:
> >
> > Years ago I created a widget that allows me to accept a line without
> committing it to the history:
> [...]
> > So I wonder, what would be a better implementation?
>
> How about something along the lines of:
>
> execute_no_history() {
> setopt hist_ignore_space
> zle .accept-line
> }
> zshaddhistory() {
> [[ -o hist_ignore_space ]] && return 2
> }
> precmd() {
> unsetopt hist_ignore_space
> }
>
> You can use a global variable instead of any otherwise-unused setopt
> if you prefer.
>
[-- Attachment #2: Type: text/html, Size: 1421 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: widget accept-no-history
2023-08-24 14:01 ` Pier Paolo Grassi
@ 2023-08-24 17:47 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2023-08-24 17:47 UTC (permalink / raw)
To: Pier Paolo Grassi; +Cc: Zsh-Users List
On Thu, Aug 24, 2023 at 7:01 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> I see, I wasn't aware of the zshaddhistory hook
Just one quick addition:
>> zshaddhistory() {
>> [[ -o hist_ignore_space ]] && return 2
>> }
That needs to be
zshaddhistory() {
[[ -o hist_ignore_space ]] && return 2
return 0
}
Otherwise the failed [[ -o ]] test will cause a return of 1, which
will cause the line to be skipped entirely.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-24 17:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23 14:40 widget accept-no-history Pier Paolo Grassi
2023-08-24 3:20 ` Bart Schaefer
2023-08-24 14:01 ` Pier Paolo Grassi
2023-08-24 17:47 ` Bart Schaefer
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).