From ea0fb003717b0938ef589d23f4efbb197f8aa495 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Wed, 25 Sep 2019 08:02:35 -0300 Subject: [PATCH] Autoselect on single option (#68) Based on #https://github.com/denisidoro/navi/pull/53 by @nikush. Fixes #44. --- src/opts.sh | 4 +++- src/ui.sh | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/opts.sh b/src/opts.sh index d66e188..854c58d 100644 --- a/src/opts.sh +++ b/src/opts.sh @@ -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" } diff --git a/src/ui.sh b/src/ui.sh index bb7c67a..658ecb5 100644 --- a/src/ui.sh +++ b/src/ui.sh @@ -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