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









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