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 Mon, Oct 28, 2024 at 7:22 PM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Mon, Oct 28, 2024 at 7:15 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > 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?
>
> I inferred it from this prior interaction:
> https://github.com/romkatv/zsh4humans/issues/329#issuecomment-2439657976.
> This comment and the ones below it. I really need to try this for
> myself and not speculate.

I've tried it myself and can confirm this issue: the history
associative array updates only when you execute a non-empty command;
it does not update when you simply press ENTER, even when
share_history is set.

To reproduce:

1. Run `zsh -f` in two terminals. I'll refer to them as Terminal 1 and
Terminal 2 below.
2. Paste this code into each of the two terminals.

    setopt share_history
    HISTSIZE=1000
    SAVEHIST=1000
    HISTFILE=/tmp/hist

    zmodload zsh/parameter

    function test-history() {
      zle up-history
      zle -M -- "${history[${#history}]}"
    }

    zle -N test-history
    bindkey '^T' test-history

3. Run `: 1` in Terminal 1.
4. Run `: 2` in Terminal 2.
5. Press ENTER in Terminal 1 without entering a command.
6. Press Ctrl-T in Terminal 1.

Expected:

    adam% : 2
    : 2

Actual:

    adam% : 2
    : 1

We can see that `zle up-history` sees the last history event, which
was written by Terminal 2, but `history` does not have it.

Roman




Messages sorted by: Reverse Date, Date, Thread, Author