navi/shell/navi.plugin.bash
Denis Isidoro ed0759f9e3
Fix multiline behavior in the bash widget (#308)
Fixes #306 

This only happens when using the bash widget
2020-03-24 08:38:42 -03:00

26 lines
No EOL
602 B
Bash

#!/usr/bin/env bash
__call_navi() {
local -r result="$(navi --print)"
local -r linecount="$(echo "$result" | wc -l)"
if [[ "$linecount" -lt 2 ]]; then
printf "$result"
return 0
fi
IFS=$'\n'
local i=1;
for line in $result; do
if echo "$line" | grep -q '\\$'; then
printf "${line::-1} "
elif [[ "$i" -eq "$linecount" ]]; then
printf "$line "
else
printf "${line}; "
fi
i=$((i+1))
done
}
bind '"\C-g": " \C-b\C-k \C-u`__call_navi`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'