From daa5c981123654e1f844989d6d162425d974198d Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Tue, 30 Jun 2026 02:47:05 +0530 Subject: [PATCH] Bash/Fish/Zsh: avoid drawing a new line when Space-Tab completion finds no matches --- CHANGELOG.md | 1 + templates/bash.txt | 2 +- templates/fish.txt | 2 +- templates/zsh.txt | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fe89cc..2c80d48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Zsh: skip doctor diagnostics in non-interactive shells. - Zsh: avoid inserting a trailing space when cancelling interactive Space-Tab completions. - Bash: avoid blanking the prompt when cancelling interactive Space-Tab completions. +- Bash/Fish/Zsh: avoid drawing a new line when Space-Tab completion finds no matches. ## [0.9.9] - 2026-01-31 diff --git a/templates/bash.txt b/templates/bash.txt index 7a64fad..e268a9d 100644 --- a/templates/bash.txt +++ b/templates/bash.txt @@ -178,7 +178,7 @@ 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. elif [[ -z ${COMP_WORDS[-1]} ]]; then # shellcheck disable=SC2312 - if __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")"; then + if __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}" 2>/dev/null)"; then # In case the terminal does not respond to \e[5n or another # mechanism steals the response, it is still worth completing # the directory in the command line. diff --git a/templates/fish.txt b/templates/fish.txt index 4e163a0..6cbe2da 100644 --- a/templates/fish.txt +++ b/templates/fish.txt @@ -100,7 +100,7 @@ function __zoxide_z_complete else if test (builtin count $tokens) -eq (builtin count $curr_tokens) # If the last argument is empty, use interactive selection. 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 2>/dev/null) and __zoxide_cd $result and builtin commandline --function cancel-commandline repaint and builtin history append "{{ cmd.unwrap_or("cd") }} "(string escape -- $result) &>/dev/null diff --git a/templates/zsh.txt b/templates/zsh.txt index fa81218..9cdbcc2 100644 --- a/templates/zsh.txt +++ b/templates/zsh.txt @@ -144,7 +144,7 @@ if [[ -o zle ]]; then elif [[ "${words[-1]}" == '' ]]; then # Show completions for Space-Tab. # shellcheck disable=SC2086 - __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd || \builtin true)" --interactive -- ${words[2,-1]})" || __zoxide_result='' + __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd || \builtin true)" --interactive -- ${words[2,-1]} 2>/dev/null)" || __zoxide_result='' # Set a result to ensure completion doesn't re-run compadd -Q -S "" -- ""