@@ -28,35 +28,61 @@ function __zoxide_cd() {
2828# Hook configuration for zoxide.
2929#
3030
31- {% if hook == InitHook::None -%}
32- {{ not_configured -}}
33-
34- {% else -%}
3531# Hook to add new entries to the database.
3632function __zoxide_hook() {
3733 # shellcheck disable=SC2312
3834 \command zoxide add -- "$(__zoxide_pwd)"
3935}
4036
4137# Initialize hook.
42- # shellcheck disable=SC2154
43- if [[ ${precmd_functions[(Ie)__zoxide_hook]:-} -eq 0 ]] && [[ ${chpwd_functions[(Ie)__zoxide_hook]:-} -eq 0 ]]; then
38+ \builtin typeset -ga precmd_functions
39+ \builtin typeset -ga chpwd_functions
40+
41+ # shellcheck disable=SC2034,SC2296
42+ precmd_functions=("${(@)precmd_functions:#__zoxide_hook}")
43+ # shellcheck disable=SC2034,SC2296
44+ chpwd_functions=("${(@)chpwd_functions:#__zoxide_hook}")
45+
4446{%- if hook == InitHook::Prompt %}
45- precmd_functions+=(__zoxide_hook)
47+ precmd_functions+=(__zoxide_hook)
4648{%- else if hook == InitHook::Pwd %}
47- chpwd_functions+=(__zoxide_hook)
49+ chpwd_functions+=(__zoxide_hook)
50+ {%- endif %}
51+
52+ # Report common issues.
53+ function __zoxide_doctor() {
54+ {%- if hook == InitHook::None %}
55+ return 0
56+
57+ {%- else %}
58+ [[ ${_ZO_DOCTOR:-1} -ne 0 ]] || return 0
59+
60+ {%- if hook == InitHook::Prompt %}
61+ [[ ${precmd_functions[(Ie)__zoxide_hook]:-} -eq 0 ]] || return 0
62+ {%- else if hook == InitHook::Pwd %}
63+ [[ ${chpwd_functions[(Ie)__zoxide_hook]:-} -eq 0 ]] || return 0
4864{%- endif %}
49- fi
5065
66+ _ZO_DOCTOR=0
67+ \builtin printf '%s\n' \
68+ 'zoxide: detected a possible configuration issue.' \
69+ 'Please ensure that zoxide is initialized right at the end of your shell configuration file (usually ~/.zshrc).' \
70+ '' \
71+ 'If the issue persists, consider filing an issue at:' \
72+ 'https://github.com/ajeetdsouza/zoxide/issues.' \
73+ '' \
74+ 'Disable this message by setting _ZO_DOCTOR=0.' \
75+ '' >&2
5176{%- endif %}
77+ }
5278
5379{{ section }}
5480# When using zoxide with --no-cmd, alias these internal functions as desired.
5581#
5682
5783# Jump to a directory using only keywords.
5884function __zoxide_z() {
59- # shellcheck disable=SC2199
85+ __zoxide_doctor
6086 if [[ "$#" -eq 0 ]]; then
6187 __zoxide_cd ~
6288 elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then
@@ -72,6 +98,7 @@ function __zoxide_z() {
7298
7399# Jump to a directory using interactive search.
74100function __zoxide_zi() {
101+ __zoxide_doctor
75102 \builtin local result
76103 result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${result}"
77104}
@@ -148,6 +175,6 @@ if [[ -o zle ]]; then
148175fi
149176
150177{{ section }}
151- # To initialize zoxide, add this to your configuration (usually ~/.zshrc):
178+ # To initialize zoxide, add this to your shell configuration file (usually ~/.zshrc):
152179#
153180# eval "$(zoxide init zsh)"
0 commit comments