2020-03-04 21:01:23 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-04-09 14:55:44 +00:00
|
|
|
_navi_call() {
|
2021-08-07 18:57:22 +00:00
|
|
|
local result="$(navi "$@" </dev/tty)"
|
|
|
|
printf "%s" "$result"
|
2020-03-04 21:01:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 14:55:44 +00:00
|
|
|
_navi_widget() {
|
2021-08-07 18:57:22 +00:00
|
|
|
local -r input="${READLINE_LINE}"
|
|
|
|
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
|
2020-08-13 12:14:33 +00:00
|
|
|
|
2021-08-07 18:57:22 +00:00
|
|
|
if [ -z "${last_command}" ]; then
|
|
|
|
local -r output="$(_navi_call --print)"
|
|
|
|
else
|
2021-08-09 13:47:03 +00:00
|
|
|
local -r find="${last_command}_NAVIEND"
|
2021-08-07 18:57:22 +00:00
|
|
|
local -r replacement="$(_navi_call --print --query "$last_command")"
|
|
|
|
local output="$input"
|
|
|
|
if [ -n "$replacement" ]; then
|
2021-08-09 13:47:03 +00:00
|
|
|
output="${input}_NAVIEND"
|
|
|
|
output="${output//$find/$replacement}"
|
2021-08-07 18:57:22 +00:00
|
|
|
fi
|
|
|
|
fi
|
2020-08-13 12:14:33 +00:00
|
|
|
|
2021-08-07 18:57:22 +00:00
|
|
|
READLINE_LINE="$output"
|
|
|
|
READLINE_POINT=${#READLINE_LINE}
|
2021-04-09 14:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_navi_widget_legacy() {
|
2021-08-07 18:57:22 +00:00
|
|
|
_navi_call --print
|
2020-08-13 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-07 18:57:22 +00:00
|
|
|
if [ ${BASH_VERSION:0:1} -lt 4 ]; then
|
|
|
|
bind '"\C-g": " \C-b\C-k \C-u`_navi_widget_legacy`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
|
2020-08-13 12:14:33 +00:00
|
|
|
else
|
2021-08-07 18:57:22 +00:00
|
|
|
bind -x '"\C-g": _navi_widget'
|
2021-04-09 14:55:44 +00:00
|
|
|
fi
|