zsh-users
 help / color / mirror / code / Atom feed
* shared history but recalling history in current terminal
@ 2013-11-26 20:30 shawn wilson
  2013-11-27  6:31 ` Wayne Davison
  0 siblings, 1 reply; 16+ messages in thread
From: shawn wilson @ 2013-11-26 20:30 UTC (permalink / raw)
  To: Zsh Users

So, I have 'inc_append_history' (I guess - it isn't in my zshrc but
I'm guessing it's an OMZ feature) which is great.

However, what I'd like is to be able to search a shared history but
have my up arrow use just the history in my current terminal. Is that
possible?


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-26 20:30 shared history but recalling history in current terminal shawn wilson
@ 2013-11-27  6:31 ` Wayne Davison
  2013-11-27  8:02   ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: Wayne Davison @ 2013-11-27  6:31 UTC (permalink / raw)
  To: shawn wilson; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 843 bytes --]

On Tue, Nov 26, 2013 at 12:30 PM, shawn wilson <ag4ve.us@gmail.com> wrote:

> what I'd like is to be able to search a shared history but have my up
> arrow use just the history in my current terminal. Is that possible?
>

Yes, that's possible.  I do something similar, where I have Ctrl-P/Ctrl-N
only go through local history (I leave up/down arrow going through the
shared history).


bindkey '^p' up-line-or-local-history
bindkey '^n' down-line-or-local-history

up-line-or-local-history() {
    zle set-local-history 1
    zle up-line-or-history
    zle set-local-history 0
}
zle -N up-line-or-local-history
down-line-or-local-history() {
    zle set-local-history 1
    zle down-line-or-history
    zle set-local-history 0
}
zle -N down-line-or-local-history

If you change that to bindkey the arrows, you'll get what you want.

..wayne..

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-27  6:31 ` Wayne Davison
@ 2013-11-27  8:02   ` Bart Schaefer
  2013-11-27 13:49     ` shawn wilson
  2013-11-27 19:08     ` René 'Necoro' Neumann
  0 siblings, 2 replies; 16+ messages in thread
From: Bart Schaefer @ 2013-11-27  8:02 UTC (permalink / raw)
  To: Zsh Users

On Nov 26, 10:31pm, Wayne Davison wrote:
>
> bindkey '^p' up-line-or-local-history
> 
> up-line-or-local-history() {
>     zle set-local-history 1
>     zle up-line-or-history
>     zle set-local-history 0
> }
> zle -N up-line-or-local-history

Another possibility is something like:

zle-line-init() { zle set-local-history 1 }
zle -N zle-line-init

zle-keymap-select() {
    [[ $KEYMAP = isearch ]]
    zle set-local-history $?
}
zle -N zle-keymap-select

Then incremental search is non-local history, everything else is local,
and you don't have to re-create individual keybindings.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-27  8:02   ` Bart Schaefer
@ 2013-11-27 13:49     ` shawn wilson
  2013-11-27 15:11       ` Karoly Negyesi
  2013-11-27 19:08     ` René 'Necoro' Neumann
  1 sibling, 1 reply; 16+ messages in thread
From: shawn wilson @ 2013-11-27 13:49 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

Sweet. Works great. Thanks

(Now I'm only pissed off that I put up with this for so long and
didn't ask sooner)

On Wed, Nov 27, 2013 at 3:02 AM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Nov 26, 10:31pm, Wayne Davison wrote:
>>
>> bindkey '^p' up-line-or-local-history
>>
>> up-line-or-local-history() {
>>     zle set-local-history 1
>>     zle up-line-or-history
>>     zle set-local-history 0
>> }
>> zle -N up-line-or-local-history
>
> Another possibility is something like:
>
> zle-line-init() { zle set-local-history 1 }
> zle -N zle-line-init
>
> zle-keymap-select() {
>     [[ $KEYMAP = isearch ]]
>     zle set-local-history $?
> }
> zle -N zle-keymap-select
>
> Then incremental search is non-local history, everything else is local,
> and you don't have to re-create individual keybindings.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-27 13:49     ` shawn wilson
@ 2013-11-27 15:11       ` Karoly Negyesi
  2013-11-27 15:17         ` shawn wilson
  2013-11-27 18:24         ` Bart Schaefer
  0 siblings, 2 replies; 16+ messages in thread
From: Karoly Negyesi @ 2013-11-27 15:11 UTC (permalink / raw)
  To: shawn wilson; +Cc: Bart Schaefer, Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1102 bytes --]

This is interesting to me as well. If I do what Bart suggests, do I keep the

setopt inc_append_history share_history

line or not...?


Thanks

NK


On Wed, Nov 27, 2013 at 5:49 AM, shawn wilson <ag4ve.us@gmail.com> wrote:

> Sweet. Works great. Thanks
>
> (Now I'm only pissed off that I put up with this for so long and
> didn't ask sooner)
>
> On Wed, Nov 27, 2013 at 3:02 AM, Bart Schaefer
> <schaefer@brasslantern.com> wrote:
> > On Nov 26, 10:31pm, Wayne Davison wrote:
> >>
> >> bindkey '^p' up-line-or-local-history
> >>
> >> up-line-or-local-history() {
> >>     zle set-local-history 1
> >>     zle up-line-or-history
> >>     zle set-local-history 0
> >> }
> >> zle -N up-line-or-local-history
> >
> > Another possibility is something like:
> >
> > zle-line-init() { zle set-local-history 1 }
> > zle -N zle-line-init
> >
> > zle-keymap-select() {
> >     [[ $KEYMAP = isearch ]]
> >     zle set-local-history $?
> > }
> > zle -N zle-keymap-select
> >
> > Then incremental search is non-local history, everything else is local,
> > and you don't have to re-create individual keybindings.
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-27 15:11       ` Karoly Negyesi
@ 2013-11-27 15:17         ` shawn wilson
  2013-11-27 18:24         ` Bart Schaefer
  1 sibling, 0 replies; 16+ messages in thread
From: shawn wilson @ 2013-11-27 15:17 UTC (permalink / raw)
  To: Karoly Negyesi; +Cc: Bart Schaefer, Zsh Users

I assume so - those functions don't turn those options on, so....

On Wed, Nov 27, 2013 at 10:11 AM, Karoly Negyesi <karoly@negyesi.net> wrote:
> This is interesting to me as well. If I do what Bart suggests, do I keep the
>
> setopt inc_append_history share_history
>
> line or not...?
>
>
> Thanks
>
> NK
>
>
> On Wed, Nov 27, 2013 at 5:49 AM, shawn wilson <ag4ve.us@gmail.com> wrote:
>>
>> Sweet. Works great. Thanks
>>
>> (Now I'm only pissed off that I put up with this for so long and
>> didn't ask sooner)
>>
>> On Wed, Nov 27, 2013 at 3:02 AM, Bart Schaefer
>> <schaefer@brasslantern.com> wrote:
>> > On Nov 26, 10:31pm, Wayne Davison wrote:
>> >>
>> >> bindkey '^p' up-line-or-local-history
>> >>
>> >> up-line-or-local-history() {
>> >>     zle set-local-history 1
>> >>     zle up-line-or-history
>> >>     zle set-local-history 0
>> >> }
>> >> zle -N up-line-or-local-history
>> >
>> > Another possibility is something like:
>> >
>> > zle-line-init() { zle set-local-history 1 }
>> > zle -N zle-line-init
>> >
>> > zle-keymap-select() {
>> >     [[ $KEYMAP = isearch ]]
>> >     zle set-local-history $?
>> > }
>> > zle -N zle-keymap-select
>> >
>> > Then incremental search is non-local history, everything else is local,
>> > and you don't have to re-create individual keybindings.
>
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-27 15:11       ` Karoly Negyesi
  2013-11-27 15:17         ` shawn wilson
@ 2013-11-27 18:24         ` Bart Schaefer
  1 sibling, 0 replies; 16+ messages in thread
From: Bart Schaefer @ 2013-11-27 18:24 UTC (permalink / raw)
  To: Zsh Users

On Nov 27,  7:11am, Karoly Negyesi wrote:
} 
} If I do what Bart suggests, do I keep the
} 
} setopt inc_append_history share_history
} 
} line or not...?

You keep it.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-27  8:02   ` Bart Schaefer
  2013-11-27 13:49     ` shawn wilson
@ 2013-11-27 19:08     ` René 'Necoro' Neumann
  2013-11-28  1:05       ` Bart Schaefer
  1 sibling, 1 reply; 16+ messages in thread
From: René 'Necoro' Neumann @ 2013-11-27 19:08 UTC (permalink / raw)
  To: zsh-users

Am 27.11.2013 09:02, schrieb Bart Schaefer:
> On Nov 26, 10:31pm, Wayne Davison wrote:
>>
>> bindkey '^p' up-line-or-local-history
>>
>> up-line-or-local-history() {
>>     zle set-local-history 1
>>     zle up-line-or-history
>>     zle set-local-history 0
>> }
>> zle -N up-line-or-local-history
> 
> Another possibility is something like:
> 
> zle-line-init() { zle set-local-history 1 }
> zle -N zle-line-init
> 
> zle-keymap-select() {
>     [[ $KEYMAP = isearch ]]
>     zle set-local-history $?
> }
> zle -N zle-keymap-select
> 
> Then incremental search is non-local history, everything else is local,
> and you don't have to re-create individual keybindings.
> 

Unfortunately, this seems only to work when not doing a 'RETURN' without
command in a session, because then the other sessions are imported again:

S1>ls
S2>echo muh
S1>(UP) -> ls (ESC)
S1>(RETURN)
S1>(RETURN)
S1>(UP) -> echo muh

This seems to be not completely deterministic, in some cases it does not
happen.

I tried to debug the widgets you defined, but any 'echo' or 'zle -M' I
put in there was ignored.

- René


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-27 19:08     ` René 'Necoro' Neumann
@ 2013-11-28  1:05       ` Bart Schaefer
  2013-11-28 20:44         ` René 'Necoro' Neumann
  0 siblings, 1 reply; 16+ messages in thread
From: Bart Schaefer @ 2013-11-28  1:05 UTC (permalink / raw)
  To: zsh-users

On Nov 27,  8:08pm, René 'Necoro' Neumann wrote:
> Subject: Re: shared history but recalling history in current terminal
>
> Am 27.11.2013 09:02, schrieb Bart Schaefer:
> > 
> > zle-line-init() { zle set-local-history 1 }
> > zle -N zle-line-init
> > 
> > zle-keymap-select() {
> >     [[ $KEYMAP = isearch ]]
> >     zle set-local-history $?
> > }
> > zle -N zle-keymap-select
> 
> Unfortunately, this seems only to work when not doing a 'RETURN' without
> command in a session

Hmm.  The behavior you are describing would seem to imply either that
you've omitted the "1" argument to set-local-history, or that it is
being ignored and set-local-history is simply toggling the state each
time it is called.

And indeed GDB confirms that passing the argument does not have the
expected effect.

Workaround is:

    zle-line-init() { NUMERIC=1 zle set-local-history }
    zle-keymap-select() {
      [[ $KEYMAP = isearch ]]
      NUMERIC=$? zle set-local-history
    }

The documentation says "set it with the numeric argument" so I'm not sure
if this is just Wayne's misunderstanding or if zle_hist.c needs a patch.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-28  1:05       ` Bart Schaefer
@ 2013-11-28 20:44         ` René 'Necoro' Neumann
  2013-11-28 21:33           ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: René 'Necoro' Neumann @ 2013-11-28 20:44 UTC (permalink / raw)
  To: zsh-users

Am 28.11.2013 02:05, schrieb Bart Schaefer:
> On Nov 27,  8:08pm, René 'Necoro' Neumann wrote:
>> Subject: Re: shared history but recalling history in current terminal
>>
>> Am 27.11.2013 09:02, schrieb Bart Schaefer:
>>>
>>> zle-line-init() { zle set-local-history 1 }
>>> zle -N zle-line-init
>>>
>>> zle-keymap-select() {
>>>     [[ $KEYMAP = isearch ]]
>>>     zle set-local-history $?
>>> }
>>> zle -N zle-keymap-select
>>
>> Unfortunately, this seems only to work when not doing a 'RETURN' without
>> command in a session
> 
> Hmm.  The behavior you are describing would seem to imply either that
> you've omitted the "1" argument to set-local-history, or that it is
> being ignored and set-local-history is simply toggling the state each
> time it is called.
> 
> And indeed GDB confirms that passing the argument does not have the
> expected effect.
> 
> Workaround is:
> 
>     zle-line-init() { NUMERIC=1 zle set-local-history }
>     zle-keymap-select() {
>       [[ $KEYMAP = isearch ]]
>       NUMERIC=$? zle set-local-history
>     }
> 
> The documentation says "set it with the numeric argument" so I'm not sure
> if this is just Wayne's misunderstanding or if zle_hist.c needs a patch.
> 

Hmm. Thanks. This works now in that there is no interleaving. But
interleaving is not switched on when entering incremental search. For
fun I put the following in:

zle-isearch-update() { zle -M "$KEYMAP"; }
zle -N zle-isearch-update

And this always prints 'main'. Is this a bug? (I'm running 5.0.2 here)

- René


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-28 20:44         ` René 'Necoro' Neumann
@ 2013-11-28 21:33           ` Bart Schaefer
  2013-11-30 11:03             ` René 'Necoro' Neumann
  2013-12-08 23:40             ` Jan Larres
  0 siblings, 2 replies; 16+ messages in thread
From: Bart Schaefer @ 2013-11-28 21:33 UTC (permalink / raw)
  To: zsh-users

On Nov 28,  9:44pm, René 'Necoro' Neumann wrote:
} Subject: Re: shared history but recalling history in current terminal
}
} Am 28.11.2013 02:05, schrieb Bart Schaefer:
} >     zle-keymap-select() {
} >       [[ $KEYMAP = isearch ]]
} >       NUMERIC=$? zle set-local-history
} >     }
} 
} Hmm. Thanks. This works now in that there is no interleaving. But
} interleaving is not switched on when entering incremental search.

Ah, fooey.  The isearch keymap is never actually "selected", it's just
scanned by the incremental search widgets.

Sorry for the wild goose chase.  (At least it led us to the NUMERIC vs
command-line-argument issue.)

So the right way to do this is actually

zle-line-init()  { NUMERIC=1 zle set-local-history }
zle -N zle-line-init
zle-isearch-update() { NUMERIC=0 zle set-local-history }
zle -N zle-isearch-update
zle-isearch-exit()  { NUMERIC=1 zle set-local-history }
zle -N zle-isearch-exit

Strictly speaking that runs set-local-history a lot more often than is
necessary, but doing so should be harmless.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-28 21:33           ` Bart Schaefer
@ 2013-11-30 11:03             ` René 'Necoro' Neumann
  2013-11-30 19:07               ` Bart Schaefer
  2013-12-08 23:40             ` Jan Larres
  1 sibling, 1 reply; 16+ messages in thread
From: René 'Necoro' Neumann @ 2013-11-30 11:03 UTC (permalink / raw)
  To: zsh-users

Am 28.11.2013 22:33, schrieb Bart Schaefer:
> On Nov 28,  9:44pm, René 'Necoro' Neumann wrote:
> } Subject: Re: shared history but recalling history in current terminal
> }
> } Am 28.11.2013 02:05, schrieb Bart Schaefer:
> } >     zle-keymap-select() {
> } >       [[ $KEYMAP = isearch ]]
> } >       NUMERIC=$? zle set-local-history
> } >     }
> } 
> } Hmm. Thanks. This works now in that there is no interleaving. But
> } interleaving is not switched on when entering incremental search.
> 
> Ah, fooey.  The isearch keymap is never actually "selected", it's just
> scanned by the incremental search widgets.
> 
> Sorry for the wild goose chase.  (At least it led us to the NUMERIC vs
> command-line-argument issue.)
> 
> So the right way to do this is actually
> 
> zle-line-init()  { NUMERIC=1 zle set-local-history }
> zle -N zle-line-init
> zle-isearch-update() { NUMERIC=0 zle set-local-history }
> zle -N zle-isearch-update
> zle-isearch-exit()  { NUMERIC=1 zle set-local-history }
> zle -N zle-isearch-exit
> 
> Strictly speaking that runs set-local-history a lot more often than is
> necessary, but doing so should be harmless.
> 

This works, thank you very much.

Perhaps one could add a zle-isearch-init widget? Strikes me odd, that
there isn't one.

- René


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-30 11:03             ` René 'Necoro' Neumann
@ 2013-11-30 19:07               ` Bart Schaefer
  0 siblings, 0 replies; 16+ messages in thread
From: Bart Schaefer @ 2013-11-30 19:07 UTC (permalink / raw)
  To: zsh-users

On Nov 30, 12:03pm, René 'Necoro' Neumann wrote:
}
} Perhaps one could add a zle-isearch-init widget? Strikes me odd, that
} there isn't one.

Yes, one could ... one could also turn the isearch actions into real
widgets and truly select the isearch keymap ... but which "one"?

The whole family of automatically-invoked widgets is a (relatively)
recent thing, and they were added in a very ad-hoc way (hence we have
"zle-line-finish" but "zle-isearch-exit").

I'm sure there are various side-effects that haven't been thought out;
e.g., if you start playing with up/down history or modifying $BUFFER
from inside zle-isearch-update, all sorts of oddness probably results.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-11-28 21:33           ` Bart Schaefer
  2013-11-30 11:03             ` René 'Necoro' Neumann
@ 2013-12-08 23:40             ` Jan Larres
  2013-12-08 23:54               ` Jan Larres
  1 sibling, 1 reply; 16+ messages in thread
From: Jan Larres @ 2013-12-08 23:40 UTC (permalink / raw)
  To: zsh-users

On 29/11/13 10:33, Bart Schaefer wrote:
> So the right way to do this is actually
>
> zle-line-init()  { NUMERIC=1 zle set-local-history }
> zle -N zle-line-init
> zle-isearch-update() { NUMERIC=0 zle set-local-history }
> zle -N zle-isearch-update
> zle-isearch-exit()  { NUMERIC=1 zle set-local-history }
> zle -N zle-isearch-exit

I am currently trying this out and noticed that if I use
history-incremental-pattern-search-backward instead of the normal
history-incremental-search-backward then disabling the local history no
longer works. Is there a way to make those two work together? I don't
want to lose the very handy pattern feature.

Thanks,
Jan


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-12-08 23:40             ` Jan Larres
@ 2013-12-08 23:54               ` Jan Larres
  2013-12-10  7:09                 ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: Jan Larres @ 2013-12-08 23:54 UTC (permalink / raw)
  To: zsh-users

On 09/12/13 12:40, Jan Larres wrote:
> On 29/11/13 10:33, Bart Schaefer wrote:
>> So the right way to do this is actually
>>
>> zle-line-init()  { NUMERIC=1 zle set-local-history }
>> zle -N zle-line-init
>> zle-isearch-update() { NUMERIC=0 zle set-local-history }
>> zle -N zle-isearch-update
>> zle-isearch-exit()  { NUMERIC=1 zle set-local-history }
>> zle -N zle-isearch-exit
>
> I am currently trying this out and noticed that if I use
> history-incremental-pattern-search-backward instead of the normal
> history-incremental-search-backward then disabling the local history no
> longer works. Is there a way to make those two work together? I don't
> want to lose the very handy pattern feature.

After some more investigation I noticed that unsetting local-history
does actually work, but re-running the widget after entering something
does not. So if I have this in my zshrc:

  bindkey '^r' history-incremental-pattern-search-backward

If I then press ^r and enter some word it gets correctly found in the
global history, but if I press ^r again to search for an earlier
occurence it always fails. Is there any way to fix this?

Thanks,
Jan


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: shared history but recalling history in current terminal
  2013-12-08 23:54               ` Jan Larres
@ 2013-12-10  7:09                 ` Bart Schaefer
  0 siblings, 0 replies; 16+ messages in thread
From: Bart Schaefer @ 2013-12-10  7:09 UTC (permalink / raw)
  To: zsh-users

On Dec 9, 12:54pm, Jan Larres wrote:
} Subject: Re: shared history but recalling history in current terminal
}
} After some more investigation I noticed that unsetting local-history
} does actually work, but re-running the widget after entering something
} does not. So if I have this in my zshrc:
} 
}   bindkey '^r' history-incremental-pattern-search-backward
} 
} If I then press ^r and enter some word it gets correctly found in the
} global history, but if I press ^r again to search for an earlier
} occurence it always fails. Is there any way to fix this?

Since (as previously discussed) we don't have a hook for isearch-init,
the only way to fix that one is to rebind the widget:

    history-incremental-pattern-search-backward() {
	if [[ $LASTWIDGET != history-incremental-pattern-search-backward ]]
	then NUMERIC=0 zle set-local-history
	fi
	zle .history-incremental-pattern-search-backward "$@"
    }
    zle -N history-incremental-pattern-search-backward

I haven't actually tested that but it should be close to something that
works ...


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2013-12-10  7:09 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-26 20:30 shared history but recalling history in current terminal shawn wilson
2013-11-27  6:31 ` Wayne Davison
2013-11-27  8:02   ` Bart Schaefer
2013-11-27 13:49     ` shawn wilson
2013-11-27 15:11       ` Karoly Negyesi
2013-11-27 15:17         ` shawn wilson
2013-11-27 18:24         ` Bart Schaefer
2013-11-27 19:08     ` René 'Necoro' Neumann
2013-11-28  1:05       ` Bart Schaefer
2013-11-28 20:44         ` René 'Necoro' Neumann
2013-11-28 21:33           ` Bart Schaefer
2013-11-30 11:03             ` René 'Necoro' Neumann
2013-11-30 19:07               ` Bart Schaefer
2013-12-08 23:40             ` Jan Larres
2013-12-08 23:54               ` Jan Larres
2013-12-10  7:09                 ` 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).