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 30112
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>, Langbart <Langbart@xxxxxxxxxxxxxx>
- Subject: Re: Foreign Commands Not Appearing in 'history' Array When 'sharehistory' Option is Enabled Until a Command is Entered
- Date: Sun, 24 Nov 2024 08:41:00 +0100
- Archived-at: <https://zsh.org/users/30112>
- In-reply-to: <CAN=4vMoM+D99FBnQUds4r5750X9A-6otixayM92_RQnzu7eApA@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> <CAN=4vMoM+D99FBnQUds4r5750X9A-6otixayM92_RQnzu7eApA@mail.gmail.com>
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