Use fzf by default for build-dir selector

This commit is contained in:
Kenneth Benzie 2024-05-01 14:27:19 +01:00
parent f50db402af
commit 0efb635f02

View File

@ -85,6 +85,18 @@ EOF
if [[ ${#local_build_dirs} -eq 0 ]]; then
error "no build directories found"; return 1
elif [[ ${#local_build_dirs} -gt 1 ]]; then
if command -v fzf &> /dev/null; then
# Use fzf to select a build directory
local_build_dir=$(
printf '%s\n' "${local_build_dir[@]}" $local_build_dirs |
fzf --layout=reverse --info=hidden --border=rounded \
--height=$(( ${#local_build_dirs} + 5 ))
)
if [[ $? -ne 0 ]]; then
return 1
fi
else
# Fallback to zcurses selector when fzf is not available
zmodload zsh/curses && {
# Get the size of the terminal
local size=`stty size`
@ -138,14 +150,16 @@ EOF
zcurses delwin build-dir
zcurses end
}
fi
fi
# On success setup the build directory for use
if [[ $? -eq 0 ]]; then
# Set the build directory from selection if empty
[[ -z $local_build_dir ]] && \
local_build_dir=${local_build_dirs[$index+1]}
fi
fi
fi
fi
# If `build.ninja` exists in alias `ninja`, return.
local build
@ -176,7 +190,6 @@ EOF
if [[ -n $do_build ]]; then
eval build
fi
fi
}
# Build then run a target residing in `~build/bin`.