2020-03-04 21:01:23 +00:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
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"
|
2021-04-05 13:11:31 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 14:55:44 +00:00
|
|
|
_navi_widget() {
|
2021-08-07 18:57:22 +00:00
|
|
|
local -r input="${LBUFFER}"
|
|
|
|
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
|
|
|
|
local replacement="$last_command"
|
2021-04-05 13:11:31 +00:00
|
|
|
|
2021-08-07 18:57:22 +00:00
|
|
|
if [ -z "$last_command" ]; then
|
|
|
|
replacement="$(_navi_call --print)"
|
|
|
|
elif [ "$LASTWIDGET" = "_navi_widget" ] && [ "$input" = "$previous_output" ]; then
|
|
|
|
replacement="$(_navi_call --print --query "$last_command")"
|
|
|
|
else
|
|
|
|
replacement="$(_navi_call --print --best-match --query "$last_command")"
|
|
|
|
fi
|
2021-04-05 13:11:31 +00:00
|
|
|
|
2021-08-07 18:57:22 +00:00
|
|
|
if [ -n "$replacement" ]; then
|
2021-08-09 13:47:03 +00:00
|
|
|
local -r find="${last_command}_NAVIEND"
|
|
|
|
previous_output="${input}_NAVIEND"
|
|
|
|
previous_output="${previous_output//$find/$replacement}"
|
2021-08-07 18:57:22 +00:00
|
|
|
else
|
|
|
|
previous_output="$input"
|
|
|
|
fi
|
2021-04-05 13:11:31 +00:00
|
|
|
|
2021-08-07 18:57:22 +00:00
|
|
|
zle kill-whole-line
|
|
|
|
LBUFFER="${previous_output}"
|
|
|
|
region_highlight=("P0 100 bold")
|
|
|
|
zle redisplay
|
2021-04-05 13:11:31 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 14:55:44 +00:00
|
|
|
zle -N _navi_widget
|
|
|
|
bindkey '^g' _navi_widget
|