-
Notifications
You must be signed in to change notification settings - Fork 553
Expand file tree
/
Copy pathnavi.plugin.bash
More file actions
39 lines (33 loc) · 1000 Bytes
/
Copy pathnavi.plugin.bash
File metadata and controls
39 lines (33 loc) · 1000 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
37
38
39
#!/usr/bin/env bash
_navi_call() {
local result="$(navi "$@" </dev/tty)"
printf "%s" "$result"
}
_navi_widget() {
local -r input="${READLINE_LINE}"
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
if [ -z "${last_command}" ]; then
local -r output="$(_navi_call --print)"
else
local -r find="${last_command}_NAVIEND"
local -r replacement="$(_navi_call --print --query "$last_command")"
local output="$input"
if [ -n "$replacement" ]; then
output="${input}_NAVIEND"
output=$(
shopt -u patsub_replacement
printf '%s' "${output//"$find"/"$replacement"}"
)
fi
fi
READLINE_LINE="$output"
READLINE_POINT=${#READLINE_LINE}
}
_navi_widget_legacy() {
_navi_call --print
}
if [ ${BASH_VERSION:0:1} -lt 4 ]; then
bind '"__NAVI_KEY__": " \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
bind -x '"__NAVI_KEY__": _navi_widget'
fi