Skip to content

Commit

Permalink
Make it work without column
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro committed Oct 28, 2019
1 parent e9ed64b commit 72f75b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion navi
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
Expand Down
2 changes: 1 addition & 1 deletion src/selection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
6 changes: 5 additions & 1 deletion src/str.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ str::remove_empty_lines() {
sed '/^$/d'
}

str::last_line() {
tail -n1
}

str::as_column() {
local -r txt="$(cat)"
local -r separator="$1"

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
}

Expand Down

0 comments on commit 72f75b6

Please sign in to comment.