Use compadd method
This commit is contained in:
parent
486e04e3c8
commit
7724267273
|
|
@ -87,8 +87,10 @@ edit:add-var {{cmd}}~ $__zoxide_z~
|
||||||
edit:add-var {{cmd}}i~ $__zoxide_zi~
|
edit:add-var {{cmd}}i~ $__zoxide_zi~
|
||||||
|
|
||||||
# Load completions.
|
# Load completions.
|
||||||
{# zoxide-based completions are currently not possible, because Elvish only
|
{#-
|
||||||
# prints a completion if the current token is a prefix of it. -#}
|
zoxide-based completions are currently not possible, because Elvish only prints
|
||||||
|
a completion if the current token is a prefix of it.
|
||||||
|
#}
|
||||||
fn __zoxide_z_complete {|@rest|
|
fn __zoxide_z_complete {|@rest|
|
||||||
if (!= (builtin:count $rest) 2) {
|
if (!= (builtin:count $rest) 2) {
|
||||||
builtin:return
|
builtin:return
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,10 @@ function __zoxide_hook {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialize hook.
|
# Initialize hook.
|
||||||
{# Initialize $__zoxide_hooked if it does not exist. Removing this will cause
|
{#-
|
||||||
# an unset variable error in StrictMode. #}
|
Initialize $__zoxide_hooked if it does not exist. Removing this will cause an
|
||||||
|
unset variable error in StrictMode.
|
||||||
|
#}
|
||||||
$__zoxide_hooked = (Get-Variable __zoxide_hooked -ValueOnly -ErrorAction SilentlyContinue)
|
$__zoxide_hooked = (Get-Variable __zoxide_hooked -ValueOnly -ErrorAction SilentlyContinue)
|
||||||
if ($__zoxide_hooked -ne 1) {
|
if ($__zoxide_hooked -ne 1) {
|
||||||
$__zoxide_hooked = 1
|
$__zoxide_hooked = 1
|
||||||
|
|
|
||||||
|
|
@ -108,12 +108,14 @@ if [[ -o zle ]]; then
|
||||||
\builtin local result
|
\builtin local result
|
||||||
# shellcheck disable=SC2086,SC2312
|
# shellcheck disable=SC2086,SC2312
|
||||||
if result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -i -- ${words[2,-1]})"; then
|
if result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -i -- ${words[2,-1]})"; then
|
||||||
__zoxide_result="${result}"
|
result="${__zoxide_z_prefix}${result}"
|
||||||
|
# shellcheck disable=SC2296
|
||||||
|
compadd -Q "${(q-)result}"
|
||||||
else
|
else
|
||||||
__zoxide_result=''
|
{#-
|
||||||
fi
|
zsh-autocomplete calls the completion function multiple times if no match is
|
||||||
if [[ -v functions[.autocomplete._complete] ]]; then
|
returned.
|
||||||
# zsh-autocomplete needs a match or it will run __zoxide_z_complete multiple times
|
#}
|
||||||
compadd ""
|
compadd ""
|
||||||
fi
|
fi
|
||||||
\builtin printf '\e[5n'
|
\builtin printf '\e[5n'
|
||||||
|
|
@ -121,9 +123,6 @@ if [[ -o zle ]]; then
|
||||||
}
|
}
|
||||||
|
|
||||||
function __zoxide_z_complete_helper() {
|
function __zoxide_z_complete_helper() {
|
||||||
\builtin local result="${__zoxide_z_prefix}${__zoxide_result}"
|
|
||||||
# shellcheck disable=SC2296
|
|
||||||
[[ -n "${__zoxide_result}" ]] && LBUFFER="${LBUFFER}${(q-)result}"
|
|
||||||
\builtin zle reset-prompt
|
\builtin zle reset-prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue