blob: 9bf05796fca077e1c05b7df20a3d1d4c28e853c3 (
plain) (
blame)
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
|
# Save clap-generated function so we can delegate non-dynamic cases.
functions[_rsp_clap]=$functions[_rsp]
_rsp() {
case $words[2] in
play|queue)
if (( CURRENT > 2 )); then
_rsp_complete_args
return 0
fi
;;
esac
_rsp_clap "$@"
}
_rsp_complete_args() {
setopt localoptions
setopt nobanghist
local -a args=("${(@)words[3,$CURRENT]}")
local cur="${(j: :)args}"
local cur_clean="${cur//\\/}"
local -a suggestions
suggestions=("${(@f)"$(rsp db-complete "$cur" 2>/dev/null)"}")
# Filter out empty entries (e.g. from empty command output)
local -a filtered=()
for s in "${suggestions[@]}"; do
if [[ -n "$s" ]]; then
filtered+=("$s")
fi
done
suggestions=("${filtered[@]}")
if (( ${#suggestions} )); then
local noslash="${cur_clean//\/}"
local n_slashes=$(( ${#cur_clean} - ${#noslash} ))
local -a display=()
local -a vals=()
for s in "${suggestions[@]}"; do
vals+=("$s")
if [[ "$cur_clean" == */ ]]; then
local stripped="$s"
local i=0
while (( i < n_slashes )); do
stripped="${stripped#*/}"
(( i++ ))
done
display+=("$stripped")
else
display+=("$s")
fi
done
if (( ${#suggestions} > 1 )); then
compstate[insert]=menu
fi
if [[ ${vals[1]} == */ ]]; then
compadd -U -S '' -M 'm:{a-z}={A-Z} l:|=*' -d display -- "${vals[@]}"
else
compadd -U -M 'm:{a-z}={A-Z} l:|=*' -d display -- "${vals[@]}"
fi
else
compadd -U -S ''
fi
}
|