From d938fdc496ccecfe5d747500927b675d31e1835a Mon Sep 17 00:00:00 2001 From: LangLangBart <92653266+LangLangBart@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:19:47 +0100 Subject: [PATCH] fix(zsh): history loading with shared option (#4071) Fix #4061 --- shell/key-bindings.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index a4d7055..9d48392 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -108,9 +108,13 @@ fi fzf-history-widget() { local selected setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases noglob nobash_rematch 2> /dev/null - # Ensure the associative history array, which maps event numbers to the full - # history lines, is loaded, and that Perl is installed for multi-line output. - if zmodload -F zsh/parameter p:history 2>/dev/null && (( ${#commands[perl]} )); then + # Ensure the module is loaded if not already, and the required features, such + # as the associative 'history' array, which maps event numbers to full history + # lines, are set. Also, make sure Perl is installed for multi-line output. + if zmodload -F zsh/parameter p:{commands,history,options} 2>/dev/null && (( ${#commands[perl]} )); then + # Import commands from other shells if SHARE_HISTORY is enabled, as the + # 'history' array only updates after executing a non-empty command. + [[ "${options[sharehistory]}" == "on" ]] && fc -RI selected="$(printf '%s\t%s\000' "${(kv)history[@]}" | perl -0 -ne 'if (!$seen{(/^\s*[0-9]+\**\t(.*)/s, $1)}++) { s/\n/\n\t/g; print; }' | FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '\t↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m --read0") \