Make it work without column

This commit is contained in:
Denis Isidoro 2019-10-28 17:30:05 -03:00
parent e9ed64bd01
commit 72f75b6f24
3 changed files with 7 additions and 3 deletions

2
navi
View file

@ -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 "$@"

View file

@ -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}"

View file

@ -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
}