From 86623d1ea289488dcc4c57e9a1fcca62c088426b Mon Sep 17 00:00:00 2001 From: "Alpha Chen (aider)" Date: Mon, 6 Jan 2025 10:50:38 -0800 Subject: [PATCH] [zsh][zoxide] auto-jump if only one result --- .zshrc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.zshrc b/.zshrc index fa2f7ec..6b59d3a 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