mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2025-01-23 23:28:32 +00:00
Use \builtin in shells (#141)
This commit is contained in:
parent
dcdcec4a78
commit
d89605ffef
@ -8,16 +8,16 @@
|
|||||||
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
||||||
function __zoxide_pwd() {
|
function __zoxide_pwd() {
|
||||||
{%- if resolve_symlinks %}
|
{%- if resolve_symlinks %}
|
||||||
pwd -P
|
\builtin pwd -P
|
||||||
{%- else %}
|
{%- else %}
|
||||||
pwd -L
|
\builtin pwd -L
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
# cd + custom logic based on the value of _ZO_ECHO.
|
# cd + custom logic based on the value of _ZO_ECHO.
|
||||||
function __zoxide_cd() {
|
function __zoxide_cd() {
|
||||||
# shellcheck disable=SC2164
|
# shellcheck disable=SC2164
|
||||||
cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
|
\builtin cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ SECTION }}
|
{{ SECTION }}
|
||||||
@ -36,7 +36,7 @@ function __zoxide_hook() {
|
|||||||
|
|
||||||
{%- when Hook::Pwd %}
|
{%- when Hook::Pwd %}
|
||||||
function __zoxide_hook() {
|
function __zoxide_hook() {
|
||||||
local -r __zoxide_pwd_tmp="$(__zoxide_pwd)"
|
\builtin local -r __zoxide_pwd_tmp="$(__zoxide_pwd)"
|
||||||
if [ -z "${__zoxide_pwd_old}" ]; then
|
if [ -z "${__zoxide_pwd_old}" ]; then
|
||||||
__zoxide_pwd_old="${__zoxide_pwd_tmp}"
|
__zoxide_pwd_old="${__zoxide_pwd_tmp}"
|
||||||
elif [ "${__zoxide_pwd_old}" != "${__zoxide_pwd_tmp}" ]; then
|
elif [ "${__zoxide_pwd_old}" != "${__zoxide_pwd_tmp}" ]; then
|
||||||
@ -72,20 +72,20 @@ function __zoxide_z() {
|
|||||||
__zoxide_cd "${OLDPWD}"
|
__zoxide_cd "${OLDPWD}"
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
echo 'zoxide: $OLDPWD is not set'
|
\builtin echo 'zoxide: $OLDPWD is not set'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
|
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
|
||||||
__zoxide_cd "$1"
|
__zoxide_cd "$1"
|
||||||
else
|
else
|
||||||
local __zoxide_result
|
\builtin local __zoxide_result
|
||||||
__zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "${__zoxide_result}"
|
__zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "${__zoxide_result}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
function __zoxide_zi() {
|
function __zoxide_zi() {
|
||||||
local __zoxide_result
|
\builtin local __zoxide_result
|
||||||
__zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "${__zoxide_result}"
|
__zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "${__zoxide_result}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,9 +124,9 @@ function __zoxide_zri() {
|
|||||||
# Remove definitions.
|
# Remove definitions.
|
||||||
function __zoxide_unset() {
|
function __zoxide_unset() {
|
||||||
# shellcheck disable=SC1001
|
# shellcheck disable=SC1001
|
||||||
\unset -f "$@" &>{{ Opts::DEVNULL }}
|
\builtin unset -f "$@" &>{{ Opts::DEVNULL }}
|
||||||
# shellcheck disable=SC1001
|
# shellcheck disable=SC1001
|
||||||
\unset -v "$@" &>{{ Opts::DEVNULL }}
|
\builtin unset -v "$@" &>{{ Opts::DEVNULL }}
|
||||||
}
|
}
|
||||||
|
|
||||||
__zoxide_unset '{{cmd}}'
|
__zoxide_unset '{{cmd}}'
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{%- let NOT_CONFIGURED = "# -- not configured --" -%}
|
{%- let NOT_CONFIGURED = "# -- not configured --" -%}
|
||||||
|
|
||||||
{%- if hook == Hook::Pwd -%}
|
{%- if hook == Hook::Pwd -%}
|
||||||
echo "\
|
\echo "\
|
||||||
zoxide: PWD hooks are not supported on POSIX shells.
|
zoxide: PWD hooks are not supported on POSIX shells.
|
||||||
Use '--hook prompt' when initializing zoxide."
|
Use '--hook prompt' when initializing zoxide."
|
||||||
|
|
||||||
@ -15,16 +15,16 @@ zoxide: PWD hooks are not supported on POSIX shells.
|
|||||||
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
||||||
__zoxide_pwd() {
|
__zoxide_pwd() {
|
||||||
{%- if resolve_symlinks %}
|
{%- if resolve_symlinks %}
|
||||||
pwd -P
|
\pwd -P
|
||||||
{%- else %}
|
{%- else %}
|
||||||
pwd -L
|
\pwd -L
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
# cd + custom logic based on the value of _ZO_ECHO.
|
# cd + custom logic based on the value of _ZO_ECHO.
|
||||||
__zoxide_cd() {
|
__zoxide_cd() {
|
||||||
# shellcheck disable=SC2164
|
# shellcheck disable=SC2164
|
||||||
cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
|
\cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ SECTION }}
|
{{ SECTION }}
|
||||||
@ -76,7 +76,7 @@ __zoxide_z() {
|
|||||||
__zoxide_cd "${OLDPWD}"
|
__zoxide_cd "${OLDPWD}"
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
echo 'zoxide: $OLDPWD is not set'
|
\echo 'zoxide: $OLDPWD is not set'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
|
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
|
||||||
|
@ -8,15 +8,15 @@
|
|||||||
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
||||||
function __zoxide_pwd() {
|
function __zoxide_pwd() {
|
||||||
{%- if resolve_symlinks %}
|
{%- if resolve_symlinks %}
|
||||||
pwd -P
|
\builtin pwd -P
|
||||||
{%- else %}
|
{%- else %}
|
||||||
pwd -L
|
\builtin pwd -L
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
# cd + custom logic based on the value of _ZO_ECHO.
|
# cd + custom logic based on the value of _ZO_ECHO.
|
||||||
function __zoxide_cd() {
|
function __zoxide_cd() {
|
||||||
cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
|
\builtin cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ SECTION }}
|
{{ SECTION }}
|
||||||
@ -56,20 +56,20 @@ function __zoxide_z() {
|
|||||||
if [ -n "$OLDPWD" ]; then
|
if [ -n "$OLDPWD" ]; then
|
||||||
__zoxide_cd "$OLDPWD"
|
__zoxide_cd "$OLDPWD"
|
||||||
else
|
else
|
||||||
echo "zoxide: \\$OLDPWD is not set"
|
\builtin echo 'zoxide: \$OLDPWD is not set'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
|
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
|
||||||
__zoxide_cd "$1"
|
__zoxide_cd "$1"
|
||||||
else
|
else
|
||||||
local __zoxide_result
|
\builtin local __zoxide_result
|
||||||
__zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "$__zoxide_result"
|
__zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "$__zoxide_result"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
function __zoxide_zi() {
|
function __zoxide_zi() {
|
||||||
local __zoxide_result
|
\builtin local __zoxide_result
|
||||||
__zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "$__zoxide_result"
|
__zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "$__zoxide_result"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,9 +107,9 @@ function __zoxide_zri() {
|
|||||||
|
|
||||||
# Remove definitions.
|
# Remove definitions.
|
||||||
function __zoxide_unset() {
|
function __zoxide_unset() {
|
||||||
\unalias "$@" &>{{ Opts::DEVNULL }}
|
\builtin unalias "$@" &>{{ Opts::DEVNULL }}
|
||||||
\unfunction "$@" &>{{ Opts::DEVNULL }}
|
\builtin unfunction "$@" &>{{ Opts::DEVNULL }}
|
||||||
\unset "$@" &>{{ Opts::DEVNULL }}
|
\builtin unset "$@" &>{{ Opts::DEVNULL }}
|
||||||
}
|
}
|
||||||
|
|
||||||
__zoxide_unset '{{cmd}}'
|
__zoxide_unset '{{cmd}}'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user