navi/shell/navi.plugin.zsh

37 lines
1.1 KiB
Bash
Raw Normal View History

2020-03-04 21:01:23 +00:00
#!/usr/bin/env zsh
2021-04-09 14:55:44 +00:00
_navi_call() {
local result="$(navi "$@" </dev/tty)"
if [ -z "${result}" ]; then
result="$(navi --print </dev/tty)"
fi
2021-04-09 14:55:44 +00:00
printf "%s" "$result"
}
2021-04-09 14:55:44 +00:00
_navi_widget() {
local -r input="${LBUFFER}"
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
local find="$last_command"
local replacement="$last_command"
2021-04-09 14:55:44 +00:00
if [ -z "${last_command}" ]; then
replacement="$(FZF_OVERRIDES="${FZF_OVERRIDES:-} --no-select-1" _navi_call --print)"
2021-04-09 14:55:44 +00:00
elif [ "${LASTWIDGET}" = "_navi_widget" ] && [ "$input" = "$previous_output" ]; then
find="$input"
replacement="$(_navi_call --print --query "${previous_last_command:-$last_command}")"
else
2021-04-09 14:55:44 +00:00
replacement="$(_navi_call --print --best-match --query "${last_command}")"
fi
2021-04-09 14:55:44 +00:00
previous_last_command="$last_command"
previous_output="${input//$find/$replacement}"
2021-04-09 14:55:44 +00:00
zle kill-whole-line
LBUFFER="${previous_output}"
region_highlight=("P0 100 bold")
zle redisplay
}
2021-04-09 14:55:44 +00:00
zle -N _navi_widget
bindkey '^g' _navi_widget