Skip to content

Commit

Permalink
bash doctor
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza committed Jan 8, 2025
1 parent 791deec commit 6a605fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions templates/bash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,35 @@ fi

{% endif -%}

# Report common issues.
function __zoxide_doctor() {
{%- if hook == InitHook::None %}
return 0

{%- else %}
[[ ${_ZO_DOCTOR:-1} -ne 0 ]] || return 0
[[ ${PROMPT_COMMAND:=} != *'__zoxide_hook'* ]] || return 0

_ZO_DOCTOR=0
\builtin printf '%s\n' \
'zoxide: detected a possible configuration issue.' \
'Please ensure that zoxide is initialized right at the end of your shell configuration file (usually ~/.bashrc).' \
'' \
'If the issue persists, consider filing an issue at:' \
'https://github.com/ajeetdsouza/zoxide/issues' \
'' \
'Disable this message by setting _ZO_DOCTOR=0.' \
'' >&2
{%- endif %}
}

{{ section }}
# When using zoxide with --no-cmd, alias these internal functions as desired.
#

__zoxide_z_prefix='z#'

# Jump to a directory using only keywords.
function __zoxide_z() {
# shellcheck disable=SC2199
__zoxide_doctor
if [[ $# -eq 0 ]]; then
__zoxide_cd ~
elif [[ $# -eq 1 && $1 == '-' ]]; then
Expand All @@ -93,6 +113,7 @@ function __zoxide_z() {

# Jump to a directory using interactive search.
function __zoxide_zi() {
__zoxide_doctor
\builtin local result
result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${result}"
}
Expand Down Expand Up @@ -154,6 +175,6 @@ fi
{%- endmatch %}

{{ section }}
# To initialize zoxide, add this to your configuration (usually ~/.bashrc):
# To initialize zoxide, add this to your shell configuration file (usually ~/.bashrc):
#
# eval "$(zoxide init bash)"
2 changes: 1 addition & 1 deletion templates/zsh.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function __zoxide_doctor() {
'Please ensure that zoxide is initialized right at the end of your shell configuration file (usually ~/.zshrc).' \
'' \
'If the issue persists, consider filing an issue at:' \
'https://github.com/ajeetdsouza/zoxide/issues.' \
'https://github.com/ajeetdsouza/zoxide/issues' \
'' \
'Disable this message by setting _ZO_DOCTOR=0.' \
'' >&2
Expand Down

0 comments on commit 6a605fc

Please sign in to comment.