mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2025-01-15 19:26:54 +00:00
zsh doctor
This commit is contained in:
parent
678bbdefbc
commit
791deec8ac
@ -28,10 +28,6 @@ function __zoxide_cd() {
|
|||||||
# Hook configuration for zoxide.
|
# Hook configuration for zoxide.
|
||||||
#
|
#
|
||||||
|
|
||||||
{% if hook == InitHook::None -%}
|
|
||||||
{{ not_configured -}}
|
|
||||||
|
|
||||||
{% else -%}
|
|
||||||
# Hook to add new entries to the database.
|
# Hook to add new entries to the database.
|
||||||
function __zoxide_hook() {
|
function __zoxide_hook() {
|
||||||
# shellcheck disable=SC2312
|
# shellcheck disable=SC2312
|
||||||
@ -39,24 +35,54 @@ function __zoxide_hook() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Initialize hook.
|
# Initialize hook.
|
||||||
# shellcheck disable=SC2154
|
\builtin typeset -ga precmd_functions
|
||||||
if [[ ${precmd_functions[(Ie)__zoxide_hook]:-} -eq 0 ]] && [[ ${chpwd_functions[(Ie)__zoxide_hook]:-} -eq 0 ]]; then
|
\builtin typeset -ga chpwd_functions
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034,SC2296
|
||||||
|
precmd_functions=("${(@)precmd_functions:#__zoxide_hook}")
|
||||||
|
# shellcheck disable=SC2034,SC2296
|
||||||
|
chpwd_functions=("${(@)chpwd_functions:#__zoxide_hook}")
|
||||||
|
|
||||||
{%- if hook == InitHook::Prompt %}
|
{%- if hook == InitHook::Prompt %}
|
||||||
precmd_functions+=(__zoxide_hook)
|
precmd_functions+=(__zoxide_hook)
|
||||||
{%- else if hook == InitHook::Pwd %}
|
{%- else if hook == InitHook::Pwd %}
|
||||||
chpwd_functions+=(__zoxide_hook)
|
chpwd_functions+=(__zoxide_hook)
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Report common issues.
|
||||||
|
function __zoxide_doctor() {
|
||||||
|
{%- if hook == InitHook::None %}
|
||||||
|
return 0
|
||||||
|
|
||||||
|
{%- else %}
|
||||||
|
[[ ${_ZO_DOCTOR:-1} -ne 0 ]] || return 0
|
||||||
|
|
||||||
|
{%- if hook == InitHook::Prompt %}
|
||||||
|
[[ ${precmd_functions[(Ie)__zoxide_hook]:-} -eq 0 ]] || return 0
|
||||||
|
{%- else if hook == InitHook::Pwd %}
|
||||||
|
[[ ${chpwd_functions[(Ie)__zoxide_hook]:-} -eq 0 ]] || return 0
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
_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 ~/.zshrc).' \
|
||||||
|
'' \
|
||||||
|
'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 }}
|
{{ section }}
|
||||||
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||||
#
|
#
|
||||||
|
|
||||||
# Jump to a directory using only keywords.
|
# Jump to a directory using only keywords.
|
||||||
function __zoxide_z() {
|
function __zoxide_z() {
|
||||||
# shellcheck disable=SC2199
|
__zoxide_doctor
|
||||||
if [[ "$#" -eq 0 ]]; then
|
if [[ "$#" -eq 0 ]]; then
|
||||||
__zoxide_cd ~
|
__zoxide_cd ~
|
||||||
elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then
|
elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then
|
||||||
@ -72,6 +98,7 @@ function __zoxide_z() {
|
|||||||
|
|
||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
function __zoxide_zi() {
|
function __zoxide_zi() {
|
||||||
|
__zoxide_doctor
|
||||||
\builtin local result
|
\builtin local result
|
||||||
result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${result}"
|
result="$(\command zoxide query --interactive -- "$@")" && __zoxide_cd "${result}"
|
||||||
}
|
}
|
||||||
@ -148,6 +175,6 @@ if [[ -o zle ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
{{ section }}
|
{{ section }}
|
||||||
# To initialize zoxide, add this to your configuration (usually ~/.zshrc):
|
# To initialize zoxide, add this to your shell configuration file (usually ~/.zshrc):
|
||||||
#
|
#
|
||||||
# eval "$(zoxide init zsh)"
|
# eval "$(zoxide init zsh)"
|
||||||
|
Loading…
Reference in New Issue
Block a user