diff options
author | Denis Isidoro <denisidoro@users.noreply.github.com> | 2019-10-02 12:14:07 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-02 12:14:07 -0300 |
commit | 8e606a50badddd7c4802217ef7739c23d6f38dbe (patch) | |
tree | c21a2823bdbf2e8178ab544e50dc74b469e27cbc | |
parent | 56da7299659d9ea45e3076c001016cf81b997a6a (diff) |
Limit cheat for selection (#102)
Say we have a cheat with a free input for `<foo>` and there's another cheat with suggestions for `<foo>`. If you select a command from the first cheat, the suggestions in the second cheat would be used, before this PR.
-rwxr-xr-x | src/cheat.sh | 11 | ||||
-rw-r--r-- | src/misc.sh | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/cheat.sh b/src/cheat.sh index cce61ba..6409435 100755 --- a/src/cheat.sh +++ b/src/cheat.sh @@ -51,7 +51,15 @@ cheat::pretty() { /^%/ { tags=" ["substr($0, 3)"]"; next } /^#/ { print color(4, $0) color(60, tags); next } /^\$/ { next } - NF { print color(7, $0) color(60, tags); next }' + NF { print color(7, $0) color(60, tags); next }' +} + +cheat::_until_percentage() { + awk 'BEGIN { count=0; } + + /^%/ { if (count >= 1) exit; + else { count++; print $0; next; } } + { print $0 }' } cheat::from_selection() { @@ -62,5 +70,6 @@ cheat::from_selection() { echo "$cheats" \ | grep "% ${tags}" -A99999 \ + | cheat::_until_percentage \ || (echoerr "No valid cheatsheet!"; exit 67) } diff --git a/src/misc.sh b/src/misc.sh index 669fcd7..c1b8524 100644 --- a/src/misc.sh +++ b/src/misc.sh @@ -26,4 +26,10 @@ echoerr() { url::open() { local -r cmd="$(platform::existing_command "${BROWSER:-}" xdg-open open google-chrome firefox)" "$cmd" "$@" +} + +tap() { + local -r input="$(cat)" + echoerr "$input" + echo "$input" }
\ No newline at end of file |