Add fallback widget for bash < 4 (#375)

This commit is contained in:
Denis Isidoro 2020-08-13 09:14:33 -03:00 committed by GitHub
parent 13a3b9d949
commit 4c0151c95c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,4 +16,31 @@ _call_navi() {
fi
}
bind -x '"\C-g": _call_navi'
__call_navi_legacy_versions() {
local -r result="$(navi --print)"
local -r linecount="$(echo "$result" | wc -l)"
if [[ "$linecount" -lt 2 ]]; then
printf "%s" "$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
}
if [ ${BASH_VERSION:0:1} -lt 4 ]; then
bind '"\C-g": " \C-b\C-k \C-u`__call_navi_legacy_versions`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
else
bind -x '"\C-g": _call_navi'
fi