romkatv / zsh4humans

A turnkey configuration for Zsh
MIT License
1.76k stars 113 forks source link

Mismatch in global history with Ctrl+R vs builtin fc command #329

Open LangLangBart opened 5 days ago

LangLangBart commented 5 days ago

This issue report is similar to a comment on another issue: https://github.com/romkatv/zsh4humans/issues/35#issuecomment-658142588


When SHARE_HISTORY is enabled and two terminals are open, running echo Test1 in Terminal A and fc -rl -1 in Terminal B results in the following output:


If you repeat the test but instead of running fc -rl -1 in Terminal B, you use ctrl-r (z4h-fzf-history), the command from Terminal A won't appear in the z4h-fzf-history list until a dummy command is run in Terminal B.

Adding fc -RI before $history is called in z4h-fzf-history would allow the command from Terminal A to appear after simply pressing Enter in Terminal B without executing a command. Do you agree with this approach?

--- a/fn/z4h-fzf-history
+++ b/fn/z4h-fzf-history
@@ -131,4 +131,5 @@ local preview='printf "%s" {} | command cut -f2- -d'$'\1'
       unsetopt pipe_fail
       {
+        [[ "${options[sharehistory]}" == "on" ]] && fc -RI
         # This `noglob` is a workaround for a bug in zsh that can be
         # triggered by certain corrupted history files.

typeset -pm 'HISTFILE|HISTSIZE|SAVEHIST' &&
 emulate &&
 print -r -- $(setopt) &&
 zstyle -L ':z4h:*' &&
 fc -l -2 -2 &&
 print -r -- ${#${history[@]}} ${(qqq)${history[@]}[1]}

typeset HISTFILE=/Users/paria/.dotfiles/zsh/.zsh_history
typeset -i10 HISTSIZE=1000000000
typeset -i10 SAVEHIST=1000000000
zsh
alwaystoend autocd autopushd noautoremoveslash nobeep nobgnice cbases extendedglob extendedhistory noflowcontrol noglobalrcs histexpiredupsfirst histfcntllock histfindnodups histignoredups histignorespace histsavenodups histverify interactive interactivecomments nolisttypes login promptsubst sharehistory shinstdin typesetsilent
zstyle :z4h: auto-update no
zstyle ':z4h:ssh:*' enable no
zstyle :z4h:direnv enable no
zstyle ':z4h:*' fzf-command _fzf_sanitized
zstyle :z4h:bindkey keyboard mac
zstyle :z4h: start-tmux no
zstyle :z4h: term-shell-integration yes
14532  echo Test1
14532 "echo Test101"

Related

romkatv commented 5 days ago

How does the regular Ctrl-R in zsh behave?

LangLangBart commented 5 days ago

How does the regular Ctrl-R in zsh behave?

pressing Enter in Terminal B is enough

romkatv commented 5 days ago

Is that different from Crtl-R in z4h?

LangLangBart commented 5 days ago

Yes, one has to enter a command so that the $history array gets updated.