Fix interactive completion with zsh-autocomplete (#449)

This commit is contained in:
Aaron Kollasch 2022-09-06 03:48:44 -04:00 committed by GitHub
parent 0e21153107
commit 1d102d4ad2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 15 deletions

View File

@ -7,6 +7,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- zsh: completions clashing with `zsh-autocomplete`.
## [0.8.3] - 2022-09-02
### Added

View File

@ -87,8 +87,10 @@ edit:add-var {{cmd}}~ $__zoxide_z~
edit:add-var {{cmd}}i~ $__zoxide_zi~
# 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|
if (!= (builtin:count $rest) 2) {
builtin:return

View File

@ -38,8 +38,10 @@ function __zoxide_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)
if ($__zoxide_hooked -ne 1) {
$__zoxide_hooked = 1

View File

@ -108,23 +108,21 @@ if [[ -o zle ]]; then
\builtin local result
# shellcheck disable=SC2086,SC2312
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
__zoxide_result=''
{#-
zsh-autocomplete calls the completion function multiple times if no match is
returned.
#}
compadd ""
fi
\builtin printf '\e[5n'
fi
}
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 -N __zoxide_z_complete_helper
\builtin bindkey "\e[0n" __zoxide_z_complete_helper
\builtin bindkey "\e[0n" 'reset-prompt'
if [[ "${+functions[compdef]}" -ne 0 ]]; then
\compdef -d {{cmd}}
\compdef -d {{cmd}}i