fix(per-directory-history): move fc -p out of zshaddhistory hook

Calling fc -p inside the zshaddhistory hook on every command
corrupts the preexec hook mechanism, causing preexec_functions
to receive an empty $1.

Move fc -p to set-directory-history and set-global-history
initialization functions where they execute once per toggle.

Fixes #12926
This commit is contained in:
御风 2026-06-14 10:21:19 +08:00
commit 18e1124c3d

View file

@ -128,7 +128,6 @@ function _per-directory-history-addhistory() {
fc -AI $HISTFILE fc -AI $HISTFILE
fc -AI $_per_directory_history_directory fc -AI $_per_directory_history_directory
fi fi
fc -p $_per_directory_history_directory
fi fi
} }
@ -153,6 +152,7 @@ function _per-directory-history-set-directory-history() {
HISTSIZE=$original_histsize HISTSIZE=$original_histsize
if [[ -e "$_per_directory_history_directory" ]]; then if [[ -e "$_per_directory_history_directory" ]]; then
fc -R "$_per_directory_history_directory" fc -R "$_per_directory_history_directory"
fc -p "$_per_directory_history_directory"
fi fi
} }
@ -163,6 +163,7 @@ function _per-directory-history-set-global-history() {
HISTSIZE=$original_histsize HISTSIZE=$original_histsize
if [[ -e "$HISTFILE" ]]; then if [[ -e "$HISTFILE" ]]; then
fc -R "$HISTFILE" fc -R "$HISTFILE"
fc -p "$HISTFILE"
fi fi
} }