Skip to content

Commit 3fe42e9

Browse files
committed
bash doctor
1 parent 791deec commit 3fe42e9

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

templates/bash.txt

+29-6
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ function __zoxide_cd() {
2727
{{ section }}
2828
# Hook configuration for zoxide.
2929
#
30+
{%- if hook != InitHook::None %}
3031

31-
{% if hook == InitHook::None -%}
32-
{{ not_configured }}
33-
34-
{%- else -%}
3532
# Hook to add new entries to the database.
3633
{%- if hook == InitHook::Prompt %}
3734
function __zoxide_hook() {
@@ -40,6 +37,7 @@ function __zoxide_hook() {
4037
\command zoxide add -- "$(__zoxide_pwd)"
4138
return "${retval}"
4239
}
40+
4341
{%- else if hook == InitHook::Pwd %}
4442
__zoxide_oldpwd="$(__zoxide_pwd)"
4543

@@ -60,7 +58,29 @@ if [[ ${PROMPT_COMMAND:=} != *'__zoxide_hook'* ]]; then
6058
PROMPT_COMMAND="__zoxide_hook;${PROMPT_COMMAND#;}"
6159
fi
6260

63-
{% endif -%}
61+
{%- endif %}
62+
63+
# Report common issues.
64+
function __zoxide_doctor() {
65+
{%- if hook == InitHook::None %}
66+
return 0
67+
68+
{%- else %}
69+
[[ ${_ZO_DOCTOR:-1} -ne 0 ]] || return 0
70+
[[ ${PROMPT_COMMAND:=} != *'__zoxide_hook'* ]] || return 0
71+
72+
_ZO_DOCTOR=0
73+
\builtin printf '%s\n' \
74+
'zoxide: detected a possible configuration issue.' \
75+
'Please ensure that zoxide is initialized right at the end of your shell configuration file (usually ~/.bashrc).' \
76+
'' \
77+
'If the issue persists, consider filing an issue at:' \
78+
'https://github.com/ajeetdsouza/zoxide/issues' \
79+
'' \
80+
'Disable this message by setting _ZO_DOCTOR=0.' \
81+
'' >&2
82+
{%- endif %}
83+
}
6484

6585
{{ section }}
6686
# When using zoxide with --no-cmd, alias these internal functions as desired.
@@ -70,6 +90,8 @@ __zoxide_z_prefix='z#'
7090

7191
# Jump to a directory using only keywords.
7292
function __zoxide_z() {
93+
__zoxide_doctor
94+
7395
# shellcheck disable=SC2199
7496
if [[ $# -eq 0 ]]; then
7597
__zoxide_cd ~
@@ -93,6 +115,7 @@ function __zoxide_z() {
93115

94116
# Jump to a directory using interactive search.
95117
function __zoxide_zi() {
118+
__zoxide_doctor
96119
\builtin local result
97120
result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${result}"
98121
}
@@ -154,6 +177,6 @@ fi
154177
{%- endmatch %}
155178

156179
{{ section }}
157-
# To initialize zoxide, add this to your configuration (usually ~/.bashrc):
180+
# To initialize zoxide, add this to your shell configuration file (usually ~/.bashrc):
158181
#
159182
# eval "$(zoxide init bash)"

templates/zsh.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function __zoxide_hook() {
3737
# Initialize hook.
3838
\builtin typeset -ga precmd_functions
3939
\builtin typeset -ga chpwd_functions
40-
4140
# shellcheck disable=SC2034,SC2296
4241
precmd_functions=("${(@)precmd_functions:#__zoxide_hook}")
4342
# shellcheck disable=SC2034,SC2296
@@ -69,7 +68,7 @@ function __zoxide_doctor() {
6968
'Please ensure that zoxide is initialized right at the end of your shell configuration file (usually ~/.zshrc).' \
7069
'' \
7170
'If the issue persists, consider filing an issue at:' \
72-
'https://github.com/ajeetdsouza/zoxide/issues.' \
71+
'https://github.com/ajeetdsouza/zoxide/issues' \
7372
'' \
7473
'Disable this message by setting _ZO_DOCTOR=0.' \
7574
'' >&2

0 commit comments

Comments
 (0)