From 97329b97f699a57a5390e9ef6c026f12dc7b086d Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Sat, 28 Sep 2019 23:58:00 -0300 Subject: [PATCH] Show comment for command in preview window (#98) --- cheats/brew.cheat | 16 ++++++++-------- navi | 2 +- scripts/docker | 21 +++++++++------------ src/dict.sh | 2 +- src/main.sh | 2 +- src/selection.sh | 14 ++++++++++++-- 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/cheats/brew.cheat b/cheats/brew.cheat index 8b09f8d..610ce38 100644 --- a/cheats/brew.cheat +++ b/cheats/brew.cheat @@ -6,28 +6,28 @@ brew update # upgrade brew brew upgrade -# brew info +# get info for a package brew info -# brew cask info +# get info for a cask brew cask info -# brew install +# install a package brew install -# brew caks install +# install a cask brew cask install -# brew uninstall +# uninstall a package brew uninstall -# brew cask uninstall +# uninstall a cask brew cask uninstall -# brew edit package +# edit package brew edit -# brew edit cask +# edit cask brew cask edit $ package: brew search diff --git a/navi b/navi index 2ca601a..46a7065 100755 --- a/navi +++ b/navi @@ -35,7 +35,7 @@ source "${SCRIPT_DIR}/src/main.sh" ##? full docs ##? Please refer to the README at https://github.com/denisidoro/navi -VERSION="0.10.2" +VERSION="0.10.3" NAVI_ENV="${NAVI_ENV:-prod}" opts::eval "$@" diff --git a/scripts/docker b/scripts/docker index 0088b86..87278e1 100755 --- a/scripts/docker +++ b/scripts/docker @@ -4,18 +4,15 @@ set -euo pipefail debian="${1:-false}" if $debian; then - docker run \ - -it \ - --entrypoint /bin/bash \ - -v "$(pwd):/navi" \ - debian \ - -c 'apt update; apt install -y git curl; git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && yes | ~/.fzf/install; export PATH=$PATH:/navi; bash' + image="debian" + setup_cmd="apt update; apt install -y git curl;" else - docker run \ - -it \ - --entrypoint /bin/bash \ - -v "$(pwd):/navi" \ - ellerbrock/alpine-bash-git \ - -c 'git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && yes | ~/.fzf/install; export PATH=$PATH:/navi; bash' + image="ellerbrock/alpine-bash-git" fi +docker run \ + -it \ + --entrypoint /bin/bash \ + -v "$(pwd):/navi" \ + "$image" \ + -c "${setup_cmd:-}git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && yes | ~/.fzf/install; export PATH=$PATH:/navi; bash" \ No newline at end of file diff --git a/src/dict.sh b/src/dict.sh index a1b88c9..5492504 100644 --- a/src/dict.sh +++ b/src/dict.sh @@ -48,7 +48,7 @@ dict::assoc() { local -r value="$(echo "${2:-}" | dict::_escape_value)" shift 2 - echo "$(echo "$input" | dict::dissoc "$key")${key}: ${value}\n" | dict::assoc "$@" + echo "$(echo "$input" | dict::dissoc "$key")${key}: ${value}\n" | dict::assoc "$@" } dict::get() { diff --git a/src/main.sh b/src/main.sh index 947811f..88e49a4 100644 --- a/src/main.sh +++ b/src/main.sh @@ -67,7 +67,7 @@ handler::preview() { local -r selection="$(echo "$query" | selection::dict)" local -r cheats="$(cheat::memoized_read_all)" local -r cheat="$(cheat::from_selection "$cheats" "$selection")" - [ -n "$cheat" ] && selection::cmd "$selection" "$cheat" + [ -n "$cheat" ] && selection::cmd_or_comment "$selection" "$cheat" } handler::help() { diff --git a/src/selection.sh b/src/selection.sh index 7bf140d..1179637 100644 --- a/src/selection.sh +++ b/src/selection.sh @@ -13,9 +13,10 @@ selection::core_is_comment() { grep -qE '^#' } -selection::cmd() { +selection::cmd_or_comment() { local -r selection="$1" local -r cheat="$2" + local -r always_cmd="${3:-false}" local -r core="$(echo "$selection" | dict::get core)" @@ -23,7 +24,16 @@ selection::cmd() { echo "$cheat" \ | grep "$core" -A999 \ | str::last_paragraph_line - else + elif $always_cmd; then echo "$core" + else + echo "$cheat" \ + | grep "^${core}$" -B999 \ + | tac \ + | str::last_paragraph_line fi } + +selection::cmd() { + selection::cmd_or_comment "$@" true +}