[zsh][zoxide] auto-jump if only one result
diff --git a/.zshrc b/.zshrc
index fa2f7ec7..6b59d3ad 100644
--- a/.zshrc
+++ b/.zshrc
@@ -180,12 +180,19 @@ if (( $+commands[zoxide] )); then
# https://junegunn.github.io/fzf/examples/directory-nagivation/#zoxidehttpsgithubcomajeetdsouzazoxide
unalias z 2> /dev/null
z() {
- local dir=$(
- zoxide query --list --score |
- fzf --height 40% --layout reverse --info inline \
- --nth 2.. --no-sort --query "$*" \
- --bind 'enter:become:echo {2..}'
- ) && cd "$dir"
+ # (@f) splits command output into array elements by newlines
+ local results=("${(@f)$(zoxide query --list --score "$*")}")
+
+ if (( ${#results} == 1 )); then
+ cd "$(awk '{print $NF}' <<< ${results[1]})"
+ else
+ local dir=$(
+ print -l $results |
+ fzf --height 40% --layout reverse --info inline \
+ --nth 2.. --no-sort \
+ --bind 'enter:become:echo {2..}'
+ ) && cd "$dir"
+ fi
}
fi