fix(init): new solution to eliminate a potential recursive definition

This commit is contained in:
NaroZeol 2024-11-25 11:14:08 +08:00
parent 28997dab4c
commit 393e3e659b

View File

@ -62,17 +62,27 @@ starship_zle-keymap-select() {
zle reset-prompt
}
## Check for existing keymap-select widget.
# zle-keymap-select is a special widget so it'll be "user:fnName" or nothing. Let's get fnName only.
__starship_preserved_zle_keymap_select=${widgets[zle-keymap-select]#user:}
# Define a wrapper fn to call the original widget fn and then Starship's.
starship_zle-keymap-select-wrapped() {
if [[ -n $__starship_preserved_zle_keymap_select ]] &&\
[[ "$__starship_preserved_zle_keymap_select" != "starship_zle-keymap-select-wrapped" ]]; then
# Check for redefinition of zle-keymap-select and starship_zle-keymap-select-wrapped.
if [[ -n $__starship_preserved_zle_keymap_select ]] && \
[[ $__starship_preserved_zle_keymap_select == "starship_zle-keymap-select" || \
$__starship_preserved_zle_keymap_select == "starship_zle-keymap-select-wrapped" ]]; then
__starship_preserved_zle_keymap_select=""
fi
if [[ -z $__starship_preserved_zle_keymap_select ]]; then
zle -N zle-keymap-select starship_zle-keymap-select;
else
# Define a wrapper fn to call the original widget fn and then Starship's.
starship_zle-keymap-select-wrapped() {
$__starship_preserved_zle_keymap_select "$@";
fi
starship_zle-keymap-select "$@";
}
zle -N zle-keymap-select starship_zle-keymap-select-wrapped;
starship_zle-keymap-select "$@";
}
zle -N zle-keymap-select starship_zle-keymap-select-wrapped;
fi
export STARSHIP_SHELL="zsh"