From 72f75b6f24e1d4c8513e68863dc0896479677093 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Mon, 28 Oct 2019 17:30:05 -0300 Subject: [PATCH] Make it work without column --- navi | 2 +- src/selection.sh | 2 +- src/str.sh | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/navi b/navi index 46292f3..ebda361 100755 --- a/navi +++ b/navi @@ -4,7 +4,7 @@ set -euo pipefail export NAVI_HOME="$(cd "$(dirname "$0")" && pwd)" source "${NAVI_HOME}/src/main.sh" -VERSION="0.15.1" +VERSION="0.15.2" NAVI_ENV="${NAVI_ENV:-prod}" opts::eval "$@" diff --git a/src/selection.sh b/src/selection.sh index 105eb78..ec62075 100644 --- a/src/selection.sh +++ b/src/selection.sh @@ -33,7 +33,7 @@ selection::resolve_ellipsis() { local -r cheat="$(cheat::from_tags "$cheats" "$tags")" local -r tags2="$(echo "$cheat" | head -n1 | str::sub 2)" - local -r comment2="$(echo "$cheat" | grep "$comment" | str::sub 2)" + local -r comment2="$(echo "$cheat" | grep "$comment" | str::last_line | str::sub 2)" local -r snippet2="$(echo "$cheat" | grep "$comment2" -A 999| str::last_paragraph_line)" echo "${comment2}${SELECTION_ESCAPE_STR}${snippet2}${SELECTION_ESCAPE_STR}${tags2}" diff --git a/src/str.sh b/src/str.sh index b817be1..0e39e4b 100644 --- a/src/str.sh +++ b/src/str.sh @@ -64,6 +64,10 @@ str::remove_empty_lines() { sed '/^$/d' } +str::last_line() { + tail -n1 +} + str::as_column() { local -r txt="$(cat)" local -r separator="$1" @@ -71,7 +75,7 @@ str::as_column() { if command_exists column; then echo "$txt" | column -t -s "$separator" else - echo "$txt" | awk -F "$separator" -vOFS='\t' 'NF > 0 { $1 = $1 } 1' + echo "$txt" | awk -F "$separator" -vOFS=' ' 'NF > 0 { $1 = $1 } 1' fi }