Guten Tag,
is it a bug that when the 'sharehistory' option is enabled, commands from other shells ('foreign') aren't included in the 'history' array until the user enters a command?
Consider the following widget and settings in my '.zshrc':
```sh
test-history() {
BUFFER=""
print
print -- "=== HISTORY TEST ==="
print -- "history array:"
zmodload -F zsh/parameter p:history || return 1
printf "%s\t%s\n" "${(kv)history[@]}" | head -5
print -- "--------------------"
print -- "fc command:"
print -r -- "$(fc -rl -5)"
zle accept-line
}
zle -N test-history
bindkey '^R' test-history
setopt SHARE_HISTORY
```
I open two terminals, type 'echo Test 1' in Terminal 1, switch to Terminal 2, and press 'Enter' without entering a command. Pressing 'Ctrl-R' shows that the 'history' array doesn't include the 'echo Test 1' entry.
```txt
=== HISTORY TEST ===
history array:
--------------------
fc command:
1* echo Test 1
```
After entering 'echo Test 2' in Terminal 2 and pressing 'Ctrl-R' again in Terminal 2, the output is:
```txt
=== HISTORY TEST ===
history array:
2 echo Test 2
1 echo Test 1
--------------------
fc command:
2 echo Test 2
1* echo Test 1
```
Prepending 'fc -RI' before accessing the 'history' array seems to resolve the issue. Is this the recommended workaround to ensure that the 'history' array lists its resuls like 'fc -rl ...' does ?
```sh
...
[[ "${options[sharehistory]}" == "on" ]] && fc -RI
zmodload -F zsh/parameter p:history || return 1
printf "%s\t%s\n" "${(kv)history[@]}" | head -5
...
```
Related: