diff options
author | Denis Isidoro <denisidoro@users.noreply.github.com> | 2019-10-03 12:56:36 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-03 12:56:36 -0300 |
commit | 78638c67e44ba659113fa0d41f19ad3eed041741 (patch) | |
tree | c168a1d35c7beaef36de08422e06552fde0bbb59 | |
parent | 4792621b8cf2b93e35e395f13107a854e4d9c692 (diff) |
Add fallback to tac (#108)v0.11.1
Fix #107
-rwxr-xr-x | navi | 2 | ||||
-rwxr-xr-x | scripts/lint | 1 | ||||
-rw-r--r-- | src/arg.sh | 6 | ||||
-rwxr-xr-x | src/cheat.sh | 8 | ||||
-rw-r--r-- | src/coll.sh | 2 | ||||
-rw-r--r-- | src/selection.sh | 2 | ||||
-rw-r--r-- | src/str.sh | 10 | ||||
-rw-r--r-- | test/arg_test.sh | 10 | ||||
-rw-r--r-- | test/platform_test.sh | 2 |
9 files changed, 28 insertions, 15 deletions
@@ -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.11.0" +VERSION="0.11.1" NAVI_ENV="${NAVI_ENV:-prod}" opts::eval "$@" diff --git a/scripts/lint b/scripts/lint index ca87537..601c3ed 100755 --- a/scripts/lint +++ b/scripts/lint @@ -8,7 +8,6 @@ export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" files_to_lint() { find . -iname '*.sh' find scripts/* - find shell/* echo "${SCRIPT_DIR}/test/run" echo "${SCRIPT_DIR}/navi" } @@ -36,8 +36,12 @@ arg::next() { arg::deserialize() { local arg="$1" + arg="${arg:1:${#arg}-2}" - echo "$arg" | tr "${ARG_DELIMITER}" " " | tr "${ARG_DELIMITER_2}" "'" | tr "${ARG_DELIMITER_3}" '"' + echo "$arg" \ + | tr "${ARG_DELIMITER}" " " \ + | tr "${ARG_DELIMITER_2}" "'" \ + | tr "${ARG_DELIMITER_3}" '"' } # TODO: separation of concerns diff --git a/src/cheat.sh b/src/cheat.sh index 6409435..53fb17c 100755 --- a/src/cheat.sh +++ b/src/cheat.sh @@ -51,15 +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 }' + /^%/ { if (count >= 1) exit; + else { count++; print $0; next; } } + { print $0 }' } cheat::from_selection() { diff --git a/src/coll.sh b/src/coll.sh index 24b4473..2240e17 100644 --- a/src/coll.sh +++ b/src/coll.sh @@ -46,7 +46,7 @@ coll::add() { } coll::reverse() { - tac + str::reverse_lines "$@" } coll::set() { diff --git a/src/selection.sh b/src/selection.sh index 1179637..86b5e9d 100644 --- a/src/selection.sh +++ b/src/selection.sh @@ -29,7 +29,7 @@ selection::cmd_or_comment() { else echo "$cheat" \ | grep "^${core}$" -B999 \ - | tac \ + | str::reverse_lines \ | str::last_paragraph_line fi } @@ -35,3 +35,13 @@ str::index_last_occurrence() { awk 'BEGIN{FS=""}{ for(i=1;i<=NF;i++){ if($i=="'"$char"'"){ p=i } }}END{ print p }' } + +str::reverse_lines() { + if command_exists tac; then + tac + elif command_exists perl; then + perl -e 'print reverse <>' + else + awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' + fi +} diff --git a/test/arg_test.sh b/test/arg_test.sh index 6998cc0..21bf857 100644 --- a/test/arg_test.sh +++ b/test/arg_test.sh @@ -2,15 +2,15 @@ interpolation_one_word() { echo "curl http://mysite.com/<user>/profile" \ - | arg::interpolate "user" "john" \ - | test::equals "curl http://mysite.com/john/profile" + | arg::interpolate "user" "john" \ + | test::equals "curl http://mysite.com/john/profile" } interpolation_multiple_words() { echo "cp <file> <new_file>" \ - | arg::interpolate "file" "C:/Program Files/app/foo.exe" \ - | arg::interpolate "new_file" "/mnt/c/Users/john/foo.exe" \ - | test::equals 'cp "C:/Program Files/app/foo.exe" /mnt/c/Users/john/foo.exe' + | arg::interpolate "file" "C:/Program Files/app/foo.exe" \ + | arg::interpolate "new_file" "/mnt/c/Users/john/foo.exe" \ + | test::equals 'cp "C:/Program Files/app/foo.exe" /mnt/c/Users/john/foo.exe' } test::set_suite "arg" diff --git a/test/platform_test.sh b/test/platform_test.sh index 6443d8b..3b06650 100644 --- a/test/platform_test.sh +++ b/test/platform_test.sh @@ -2,7 +2,7 @@ existing() { platform::existing_command oasida fngo ni awk aoisdn oafm \ - | test::equals awk + | test::equals awk } test::set_suite "platform" |