navi/shell/navi.plugin.bash

35 lines
932 B
Bash
Raw Normal View History

2020-03-04 18:01:23 -03:00
#!/usr/bin/env bash
2021-04-09 11:55:44 -03:00
_navi_call() {
local result="$(navi "$@" </dev/tty)"
if [ -z "${result}" ]; then
result="$(navi --print </dev/tty)"
2020-08-13 10:26:27 +02:00
fi
2021-04-09 11:55:44 -03:00
printf "%s" "$result"
2020-03-04 18:01:23 -03:00
}
2021-04-09 11:55:44 -03:00
_navi_widget() {
local -r input="${READLINE_LINE}"
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
2021-04-09 11:55:44 -03:00
if [ -z "${last_command}" ]; then
local -r output="$(_navi_call --print --fzf-overrides '--no-select-1')"
else
local -r find="$last_command"
local -r replacement="$(_navi_call --print --query "${last_command}")"
local -r output="${input//$find/$replacement}"
fi
2021-04-09 11:55:44 -03:00
READLINE_LINE="$output"
READLINE_POINT=${#READLINE_LINE}
}
_navi_widget_legacy() {
_navi_call --print
}
if [ ${BASH_VERSION:0:1} -lt 4 ]; then
2021-04-09 11:55:44 -03:00
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
2021-04-09 11:55:44 -03:00
bind -x '"\C-g": _navi_widget'
fi