fix: guard empty interactive completion results
This commit is contained in:
parent
d7458b756e
commit
5a6626cada
14
src/shell.rs
14
src/shell.rs
|
|
@ -65,6 +65,13 @@ mod tests {
|
||||||
.stderr("");
|
.stderr("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[apply(opts)]
|
||||||
|
fn bash_init_guards_empty_completion(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||||
|
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||||
|
let source = Bash(&opts).render().unwrap();
|
||||||
|
assert!(source.contains("[[ -n \"${__zoxide_result}\" ]] || return"));
|
||||||
|
}
|
||||||
|
|
||||||
#[apply(opts)]
|
#[apply(opts)]
|
||||||
fn bash_shellcheck(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
fn bash_shellcheck(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||||
|
|
@ -141,6 +148,13 @@ mod tests {
|
||||||
.stderr("");
|
.stderr("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[apply(opts)]
|
||||||
|
fn fish_init_guards_empty_completion(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||||
|
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||||
|
let source = Fish(&opts).render().unwrap();
|
||||||
|
assert!(source.contains("and test -n \"$result\""));
|
||||||
|
}
|
||||||
|
|
||||||
#[apply(opts)]
|
#[apply(opts)]
|
||||||
fn fish_fishindent(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
fn fish_fishindent(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
|
||||||
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
let opts = Opts { cmd, hook, echo, resolve_symlinks };
|
||||||
|
|
|
||||||
|
|
@ -178,18 +178,19 @@ if [[ ${BASH_VERSINFO[0]:-0} -eq 4 && ${BASH_VERSINFO[1]:-0} -ge 4 || ${BASH_VER
|
||||||
# If there is a space after the last word, use interactive selection.
|
# If there is a space after the last word, use interactive selection.
|
||||||
elif [[ -z ${COMP_WORDS[-1]} ]]; then
|
elif [[ -z ${COMP_WORDS[-1]} ]]; then
|
||||||
# shellcheck disable=SC2312
|
# shellcheck disable=SC2312
|
||||||
__zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")" && {
|
__zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")" || return
|
||||||
# In case the terminal does not respond to \e[5n or another
|
[[ -n "${__zoxide_result}" ]] || return
|
||||||
# mechanism steals the response, it is still worth completing
|
|
||||||
# the directory in the command line.
|
|
||||||
COMPREPLY=("${__zoxide_z_prefix}${__zoxide_result}/")
|
|
||||||
|
|
||||||
# Note: We here call "bind" without prefixing "\builtin" to be
|
# In case the terminal does not respond to \e[5n or another
|
||||||
# compatible with frameworks like ble.sh, which emulates Bash's
|
# mechanism steals the response, it is still worth completing
|
||||||
# builtin "bind".
|
# the directory in the command line.
|
||||||
bind -x '"\e[0n": __zoxide_z_complete_helper'
|
COMPREPLY=("${__zoxide_z_prefix}${__zoxide_result}/")
|
||||||
\builtin printf '\e[5n' >/dev/tty
|
|
||||||
}
|
# Note: We here call "bind" without prefixing "\builtin" to be
|
||||||
|
# compatible with frameworks like ble.sh, which emulates Bash's
|
||||||
|
# builtin "bind".
|
||||||
|
bind -x '"\e[0n": __zoxide_z_complete_helper'
|
||||||
|
\builtin printf '\e[5n' >/dev/tty
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ function __zoxide_z_complete
|
||||||
# If the last argument is empty, use interactive selection.
|
# If the last argument is empty, use interactive selection.
|
||||||
set -l query $tokens[2..-1]
|
set -l query $tokens[2..-1]
|
||||||
set -l result (command zoxide query --exclude (__zoxide_pwd) --interactive -- $query)
|
set -l result (command zoxide query --exclude (__zoxide_pwd) --interactive -- $query)
|
||||||
|
and test -n "$result"
|
||||||
and __zoxide_cd $result
|
and __zoxide_cd $result
|
||||||
and builtin commandline --function cancel-commandline repaint
|
and builtin commandline --function cancel-commandline repaint
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue