Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Foreign Commands Not Appearing in 'history' Array When 'sharehistory' Option is Enabled Until a Command is Entered
- X-seq: zsh-users 30111
- From: Langbart <Langbart@xxxxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: Foreign Commands Not Appearing in 'history' Array When 'sharehistory' Option is Enabled Until a Command is Entered
- Date: Sun, 24 Nov 2024 04:47:15 +0000
- Archived-at: <https://zsh.org/users/30111>
- Feedback-id: 20607877:user:proton
- In-reply-to: <CAH+w=7ZQJFXb5Te1DVxrn7kFUH9jgc=XfrOODKCDLFhRrFEnUQ@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <mwXIqemfp6p2u5-5ApP-6mjA8aw0SthwcBYnYnkHh13e_46s4ThESPJANCAKlEr2n9VBhClb1JwW_5IiYgljeAv9hJzfculpb9J6QF_lqQY=@protonmail.com> <CAH+w=7ZOwgzV9gb-Zfn-NxWmpa0yPLvevLrApMSYK9S_qAdK-g@mail.gmail.com> <CAN=4vMpYBhtKqh1BVTe01k4ssrsJYU-p8sXC=_kz6xPs_3M6yw@mail.gmail.com> <CAH+w=7ZQJFXb5Te1DVxrn7kFUH9jgc=XfrOODKCDLFhRrFEnUQ@mail.gmail.com>
On Monday, October 28th, 2024 at 6:14 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Mon, Oct 28, 2024 at 10:35 AM Roman Perepelitsa
> roman.perepelitsa@xxxxxxxxx wrote:
>
> > I believe the OP is saying that after you execute a command in one
> > terminal and press ENTER in another terminal, within that second
> > terminal all widgets that operate on history, such as
> > history-incremental-search-backward, will see the command, but the
> > `history` array won't contain it.
>
>
> That would seem to be pretty nearly impossible, because $history is
> populated by calling the same methods that the widgets use, it's not
> pre-generated/cached.
Yes, Roman described my issue accurately.
> However, I notice that the OP is doing this:
> printf "%s\t%s\n" "${(kv)history[@]}" | head -5
I have also tested it without the extra pipe, the issue is the same.
> The left hand side of that pipe is going to be forked off and might
> not see the same history list as the parent shell. However, also note
> from my "longer answer":
>
> > First, a history position (the "next" number) has already been allocated for expansion of the %h prompt escape, and loading from the shared history would have to somehow fit "above" that.
>
>
> The history number isn't incremented on an empty command, so this
> situation remains. I just re-read the OP and I don't find the
> "widgets that operate on history ... will see the command" part? What
> have I missed?
Thanks for the answers.
I have also follow-up question about the usage of 'fc -RI'. When I run this command in my widget, I notice that I can't retrieve the recent history entry by pressing the 'Up' arrow after exiting the widget.
to reproduce:
1. Add the widget below to your setup
```sh
test-widget() {
fc -RI
zle -M "History updated"
}
zle -N test-widget
bindkey '^p' test-widget
bindkey '^[[A' up-line-or-history
```
2. Press 'Control-P'
3. Press the 'Up' key notice nothing happens
PS: The issue doesn't occur in an environment where the 'HISTFILE' is undefined or the assigned file is empty. Using 'fc -R' lets me recall a recent command to the command line buffer when pressing the 'Up' key. Would that be a valid bug?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author