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)"
|
2021-04-05 13:11:31 +00:00
|
|
|
fi
|
2021-04-09 14:55:44 +00:00
|
|
|
printf "%s" "$result"
|
2021-04-05 13:11:31 +00:00
|
|
|
}
|
|
|
|
|
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-05 13:11:31 +00:00
|
|
|
|
2021-04-09 14:55:44 +00:00
|
|
|
if [ -z "${last_command}" ]; then
|
2021-06-15 13:12:22 +00:00
|
|
|
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}")"
|
2021-04-05 13:11:31 +00:00
|
|
|
else
|
2021-04-09 14:55:44 +00:00
|
|
|
replacement="$(_navi_call --print --best-match --query "${last_command}")"
|
2021-04-05 13:11:31 +00:00
|
|
|
fi
|
|
|
|
|
2021-04-09 14:55:44 +00:00
|
|
|
previous_last_command="$last_command"
|
|
|
|
previous_output="${input//$find/$replacement}"
|
2021-04-05 13:11:31 +00:00
|
|
|
|
2021-04-09 14:55:44 +00:00
|
|
|
zle kill-whole-line
|
|
|
|
LBUFFER="${previous_output}"
|
2021-04-05 13:11:31 +00:00
|
|
|
region_highlight=("P0 100 bold")
|
|
|
|
zle redisplay
|
|
|
|
}
|
|
|
|
|
2021-04-09 14:55:44 +00:00
|
|
|
zle -N _navi_widget
|
|
|
|
bindkey '^g' _navi_widget
|