Autoselect on single option (#68)

Based on #https://github.com/denisidoro/navi/pull/53 by @nikush.

Fixes #44.
This commit is contained in:
Denis Isidoro 2019-09-25 08:02:35 -03:00 committed by GitHub
parent 516578479c
commit ea0fb00371
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -13,6 +13,7 @@ opts::eval() {
local interpolation=true
local preview=true
local path="${NAVI_PATH:-${NAVI_DIR:-${SCRIPT_DIR}/cheats}}"
local autoselect=true
for arg in "$@"; do
case $wait_for in
@ -33,9 +34,10 @@ opts::eval() {
search) entry_point="search"; wait_for="search" ;;
preview) entry_point="preview"; wait_for="preview" ;;
q|query) wait_for="query" ;;
--no-autoselect) autoselect=false ;;
esac
done
OPTIONS="$(dict::new entry_point "$entry_point" print "$print" interpolation "$interpolation" preview "$preview" query "${query:-}")"
OPTIONS="$(dict::new entry_point "$entry_point" print "$print" interpolation "$interpolation" preview "$preview" autoselect "$autoselect" query "${query:-}")"
export NAVI_PATH="$path"
}

View file

@ -1,7 +1,16 @@
#!/usr/bin/env bash
ui::pick() {
fzf --height '100%' --inline-info "$@"
local -r autoselect="$(dict::get "$OPTIONS" autoselect)"
local args=()
args+=("--height")
args+=("100%")
if ${autoselect:-false}; then
args+=("--select-1")
fi
fzf "${args[@]:-}" --inline-info "$@"
}
# TODO: separation of concerns