From 5a00cb44174e6cdbae9f1434e5df2f9485e73d93 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Fri, 20 Sep 2019 14:42:51 -0300 Subject: [PATCH] Improve README (#1) --- README.md | 2 +- navi | 2 +- src/cheat.sh | 6 +++--- src/selection.sh | 13 +++++++++++-- src/ui.sh | 5 +++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0e7b160..ab333ea 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ An interactive cheatsheet tool for the command-line so that you'll never say the *- Oh, it's not in my bash history* *- Geez, it's almost what I wanted but I need to change some args* -![Demo](https://user-images.githubusercontent.com/3226564/65281359-d158f480-db08-11e9-8e69-e380d76c343b.gif) +![Demo](https://user-images.githubusercontent.com/3226564/65347073-8dbbc480-dbb4-11e9-886f-0f10d56def74.gif) **navi** allows you to browse through cheatsheets (that you may write yourself or downloaded from maintainers) and execute commands, prompting for argument values. diff --git a/navi b/navi index 427df05..a05ffbd 100755 --- a/navi +++ b/navi @@ -22,6 +22,6 @@ source "${SCRIPT_DIR}/src/main.sh" ##? --print Prevent script execution [default: false] ##? --no-interpolation Prevent argument interpolation [default: false] -VERSION="0.3.0" +VERSION="0.4.0" docs::eval "$@" main "$@" diff --git a/src/cheat.sh b/src/cheat.sh index eadc795..5e6b340 100755 --- a/src/cheat.sh +++ b/src/cheat.sh @@ -11,10 +11,10 @@ cheat::read_many() { printf("\033[%dm%s\033[0m",30+c,s) } - /^%/ { tags=substr($0, 3); next } - /^#/ { print color(3, tags"^") color(4, $0); next } + /^%/ { tags=" ["substr($0, 3)"]"; next } + /^#/ { print color(4, $0) color(60, tags); next } /^\$/ { next } - NF { print color(3, tags"^") color(7, $0); next }' "$cheat" + NF { print color(7, $0) color(60, tags); next }' "$cheat" done } diff --git a/src/selection.sh b/src/selection.sh index baab514..a0a2d3d 100644 --- a/src/selection.sh +++ b/src/selection.sh @@ -1,11 +1,20 @@ #!/usr/bin/env bash +selection::standardize() { + local readonly str="$(cat)" + + local readonly tags="$(echo "$str" | awk -F'[' '{print $NF}' | tr -d ']')" + local readonly core="$(echo "$str" | sed -e "s/ \[${tags}\]$//")" + + echo "${core}^${tags}" +} + selection::core() { - cut -d'^' -f2 + cut -d'^' -f1 } selection::tags() { - cut -d'^' -f1 + cut -d'^' -f2 } selection::core_is_comment() { diff --git a/src/ui.sh b/src/ui.sh index 608a16e..1d39c40 100644 --- a/src/ui.sh +++ b/src/ui.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash ui::pick() { - fzf --inline-info "$@" + fzf --height '100%' --inline-info "$@" } ui::select() { @@ -9,7 +9,8 @@ ui::select() { echo "$cheats" \ | cheat::read_many \ - | ui::pick -i --ansi --delimiter '\^' --with-nth 2 + | ui::pick -i --ansi \ + | selection::standardize } ui::clear_previous_line() {