Use \builtin in shells (#141)

This commit is contained in:
Ajeet D'Souza 2021-01-29 01:12:31 +05:30 committed by GitHub
parent dcdcec4a78
commit d89605ffef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 23 deletions

View File

@ -8,16 +8,16 @@
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function __zoxide_pwd() {
{%- if resolve_symlinks %}
pwd -P
\builtin pwd -P
{%- else %}
pwd -L
\builtin pwd -L
{%- endif %}
}
# cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd() {
# shellcheck disable=SC2164
cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
\builtin cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
}
{{ SECTION }}
@ -36,7 +36,7 @@ function __zoxide_hook() {
{%- when Hook::Pwd %}
function __zoxide_hook() {
local -r __zoxide_pwd_tmp="$(__zoxide_pwd)"
\builtin local -r __zoxide_pwd_tmp="$(__zoxide_pwd)"
if [ -z "${__zoxide_pwd_old}" ]; then
__zoxide_pwd_old="${__zoxide_pwd_tmp}"
elif [ "${__zoxide_pwd_old}" != "${__zoxide_pwd_tmp}" ]; then
@ -72,20 +72,20 @@ function __zoxide_z() {
__zoxide_cd "${OLDPWD}"
else
# shellcheck disable=SC2016
echo 'zoxide: $OLDPWD is not set'
\builtin echo 'zoxide: $OLDPWD is not set'
return 1
fi
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
__zoxide_cd "$1"
else
local __zoxide_result
\builtin local __zoxide_result
__zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "${__zoxide_result}"
fi
}
# Jump to a directory using interactive search.
function __zoxide_zi() {
local __zoxide_result
\builtin local __zoxide_result
__zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "${__zoxide_result}"
}
@ -124,9 +124,9 @@ function __zoxide_zri() {
# Remove definitions.
function __zoxide_unset() {
# shellcheck disable=SC1001
\unset -f "$@" &>{{ Opts::DEVNULL }}
\builtin unset -f "$@" &>{{ Opts::DEVNULL }}
# shellcheck disable=SC1001
\unset -v "$@" &>{{ Opts::DEVNULL }}
\builtin unset -v "$@" &>{{ Opts::DEVNULL }}
}
__zoxide_unset '{{cmd}}'

View File

@ -2,7 +2,7 @@
{%- let NOT_CONFIGURED = "# -- not configured --" -%}
{%- if hook == Hook::Pwd -%}
echo "\
\echo "\
zoxide: PWD hooks are not supported on POSIX shells.
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.
__zoxide_pwd() {
{%- if resolve_symlinks %}
pwd -P
\pwd -P
{%- else %}
pwd -L
\pwd -L
{%- endif %}
}
# cd + custom logic based on the value of _ZO_ECHO.
__zoxide_cd() {
# shellcheck disable=SC2164
cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
\cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
}
{{ SECTION }}
@ -76,7 +76,7 @@ __zoxide_z() {
__zoxide_cd "${OLDPWD}"
else
# shellcheck disable=SC2016
echo 'zoxide: $OLDPWD is not set'
\echo 'zoxide: $OLDPWD is not set'
return 1
fi
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then

View File

@ -8,15 +8,15 @@
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function __zoxide_pwd() {
{%- if resolve_symlinks %}
pwd -P
\builtin pwd -P
{%- else %}
pwd -L
\builtin pwd -L
{%- endif %}
}
# cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd() {
cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
\builtin cd "$@" {%- if echo %} && __zoxide_pwd {%- endif %}
}
{{ SECTION }}
@ -56,20 +56,20 @@ function __zoxide_z() {
if [ -n "$OLDPWD" ]; then
__zoxide_cd "$OLDPWD"
else
echo "zoxide: \\$OLDPWD is not set"
\builtin echo 'zoxide: \$OLDPWD is not set'
return 1
fi
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
__zoxide_cd "$1"
else
local __zoxide_result
\builtin local __zoxide_result
__zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "$__zoxide_result"
fi
}
# Jump to a directory using interactive search.
function __zoxide_zi() {
local __zoxide_result
\builtin local __zoxide_result
__zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "$__zoxide_result"
}
@ -107,9 +107,9 @@ function __zoxide_zri() {
# Remove definitions.
function __zoxide_unset() {
\unalias "$@" &>{{ Opts::DEVNULL }}
\unfunction "$@" &>{{ Opts::DEVNULL }}
\unset "$@" &>{{ Opts::DEVNULL }}
\builtin unalias "$@" &>{{ Opts::DEVNULL }}
\builtin unfunction "$@" &>{{ Opts::DEVNULL }}
\builtin unset "$@" &>{{ Opts::DEVNULL }}
}
__zoxide_unset '{{cmd}}'