Skip to content

Commit d938fdc

Browse files
authored
fix(zsh): history loading with shared option (#4071)
Fix #4061
1 parent dcb4c3d commit d938fdc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

shell/key-bindings.zsh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ fi
108108
fzf-history-widget() {
109109
local selected
110110
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases noglob nobash_rematch 2> /dev/null
111-
# Ensure the associative history array, which maps event numbers to the full
112-
# history lines, is loaded, and that Perl is installed for multi-line output.
113-
if zmodload -F zsh/parameter p:history 2>/dev/null && (( ${#commands[perl]} )); then
111+
# Ensure the module is loaded if not already, and the required features, such
112+
# as the associative 'history' array, which maps event numbers to full history
113+
# lines, are set. Also, make sure Perl is installed for multi-line output.
114+
if zmodload -F zsh/parameter p:{commands,history,options} 2>/dev/null && (( ${#commands[perl]} )); then
115+
# Import commands from other shells if SHARE_HISTORY is enabled, as the
116+
# 'history' array only updates after executing a non-empty command.
117+
[[ "${options[sharehistory]}" == "on" ]] && fc -RI
114118
selected="$(printf '%s\t%s\000' "${(kv)history[@]}" |
115119
perl -0 -ne 'if (!$seen{(/^\s*[0-9]+\**\t(.*)/s, $1)}++) { s/\n/\n\t/g; print; }' |
116120
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") \

0 commit comments

Comments
 (0)