blob: 418105dcb93813900808b12e22888d4bf1e7e351 (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/env bash
_jvn_bash_completion() {
local cur prev words cword
local line="${COMP_LINE}"
local point="${COMP_POINT}"
if [ "${point}" -gt "${#line}" ]; then
point="${#line}"
fi
words=($line)
cword=0
local i=0
local pos=0
for word in "${words[@]}"; do
local word_start=$pos
local word_end=$((pos + ${#word}))
if [ "${point}" -ge "${word_start}" ] && [ "${point}" -le "${word_end}" ]; then
cword=$i
cur="${word}"
break
fi
pos=$((pos + ${#word} + 1))
i=$((i + 1))
done
if [ "${point}" -gt "${pos}" ]; then
cword=${#words[@]}
cur=""
fi
if [ "${cword}" -gt 0 ]; then
prev="${words[$((cword-1))]}"
else
prev=""
fi
local args=(
-f "$COMP_LINE"
-C "$COMP_POINT"
-w "$cur"
-p "$prev"
-c "${words[0]}"
-i "$cword"
-a "${words[@]}"
)
local suggestions
if suggestions=$(jvn_comp "${args[@]}" 2>/dev/null); then
if [ "$suggestions" = "_file_" ]; then
compopt -o default
COMPREPLY=()
else
mapfile -t COMPREPLY < <(printf '%s\n' "$suggestions")
fi
else
COMPREPLY=()
fi
}
complete -F _jvn_bash_completion jvn
|