Use 2+ spaces as column separator (#156)

Fixes #153
This commit is contained in:
Denis Isidoro 2019-11-06 15:29:32 -03:00 committed by GitHub
parent e3f6a0418d
commit 1bd1730e8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View file

@ -79,7 +79,7 @@ arg::pick() {
if [ -n "$fn" ]; then if [ -n "$fn" ]; then
local suggestions="$(eval "$fn" 2>/dev/null)" local suggestions="$(eval "$fn" 2>/dev/null)"
if [ -n "$suggestions" ]; then if [ -n "$suggestions" ]; then
echo "$suggestions" | ui::fzf --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}" echo "$suggestions" | ui::fzf --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}" "${separator:-}"
fi fi
elif ${NAVI_USE_FZF_ALL_INPUTS:-false}; then elif ${NAVI_USE_FZF_ALL_INPUTS:-false}; then
echo "" | ui::fzf --prompt "$arg: " --print-query --no-select-1 --height 1 echo "" | ui::fzf --prompt "$arg: " --print-query --no-select-1 --height 1

View file

@ -34,4 +34,16 @@ tap() {
die() { die() {
echoerr "$@" echoerr "$@"
exit 42 exit 42
}
or() {
local -r x="$(cat)"
local -r y="${1:-}"
if [ -n "$x" ]; then
echo "$x"
elif [ $# -gt 0 ]; then
shift
echo "$y" | or "$@"
fi
} }

View file

@ -17,9 +17,10 @@ str::sub() {
str::column() { str::column() {
local -r n="${1:-}" local -r n="${1:-}"
local -r separator="$(echo "${2:-}" | or " +")"
if [ -n "$n" ]; then if [ -n "$n" ]; then
awk "{print \$$n}" awk -F "${separator:- }" "{print \$$n}"
else else
cat cat
fi fi