navi/shell/navi.plugin.bash

36 lines
908 B
Bash
Raw Permalink Normal View History

2020-03-04 21:01:23 +00:00
#!/usr/bin/env bash
2021-04-09 14:55:44 +00:00
_navi_call() {
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() {
local -r input="${READLINE_LINE}"
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
if [ -z "${last_command}" ]; then
local -r output="$(_navi_call --print)"
else
local -r find="${last_command}_NAVIEND"
local -r replacement="$(_navi_call --print --query "$last_command")"
local output="$input"
if [ -n "$replacement" ]; then
output="${input}_NAVIEND"
output="${output//$find/$replacement}"
fi
fi
READLINE_LINE="$output"
READLINE_POINT=${#READLINE_LINE}
2021-04-09 14:55:44 +00:00
}
_navi_widget_legacy() {
_navi_call --print
}
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"'
else
bind -x '"\C-g": _navi_widget'
2021-04-09 14:55:44 +00:00
fi