refactor(zsh): using add-zsh-hook instead of add hook manually (#3537)
[1]: https://github.com/starship/starship/pull/3480#discussion_r790280291 [2]: https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#Writing-Themes Signed-off-by: Coelacanthus <coelacanthus@outlook.com>
This commit is contained in:
parent
bbdb584f45
commit
589576d3eb
|
@ -52,21 +52,10 @@ prompt_starship_preexec() {
|
||||||
__starship_get_time && STARSHIP_START_TIME=$STARSHIP_CAPTURED_TIME
|
__starship_get_time && STARSHIP_START_TIME=$STARSHIP_CAPTURED_TIME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Add hook functions
|
||||||
# If precmd/preexec arrays are not already set, set them. If we don't do this,
|
autoload -Uz add-zsh-hook
|
||||||
# the code to detect whether prompt_starship_precmd is already in precmd_functions will
|
add-zsh-hook precmd prompt_starship_precmd
|
||||||
# fail because the array doesn't exist (and same for prompt_starship_preexec)
|
add-zsh-hook preexec prompt_starship_preexec
|
||||||
(( ! ${+precmd_functions} )) && precmd_functions=()
|
|
||||||
(( ! ${+preexec_functions} )) && preexec_functions=()
|
|
||||||
|
|
||||||
# If starship precmd/preexec functions are already hooked, don't double-hook them
|
|
||||||
# to avoid unnecessary performance degradation in nested shells
|
|
||||||
if [[ -z ${precmd_functions[(re)prompt_starship_precmd]} ]]; then
|
|
||||||
precmd_functions+=(prompt_starship_precmd)
|
|
||||||
fi
|
|
||||||
if [[ -z ${preexec_functions[(re)prompt_starship_preexec]} ]]; then
|
|
||||||
preexec_functions+=(prompt_starship_preexec)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set up a function to redraw the prompt if the user switches vi modes
|
# Set up a function to redraw the prompt if the user switches vi modes
|
||||||
starship_zle-keymap-select() {
|
starship_zle-keymap-select() {
|
||||||
|
|
Loading…
Reference in New Issue