-
Notifications
You must be signed in to change notification settings - Fork 553
Expand file tree
/
Copy pathnavi.plugin.zsh
More file actions
36 lines (30 loc) · 987 Bytes
/
Copy pathnavi.plugin.zsh
File metadata and controls
36 lines (30 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env zsh
_navi_call() {
local result="$(navi "$@" </dev/tty)"
printf "%s" "$result"
}
_navi_widget() {
local -r input="${LBUFFER}"
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
local replacement="$last_command"
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
if [ -n "$replacement" ]; then
local -r find="${last_command}_NAVIEND"
previous_output="${input}_NAVIEND"
previous_output="${previous_output//$find/$replacement}"
else
previous_output="$input"
fi
zle kill-whole-line
LBUFFER="${previous_output}"
region_highlight=("P0 100 bold")
zle redisplay
}
zle -N _navi_widget
bindkey '__NAVI_KEY__' _navi_widget