-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompletion
79 lines (76 loc) · 2.49 KB
/
completion
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# completion function for bluealsa-autoconfig
_bluealsa_autoconfig() {
local cur prev words cword split
_init_completion -s || return
if [[ "$prev" = "--dbus" ]] ; then
COMPREPLY=()
return
fi
COMPREPLY=( $(compgen -W "$(_parse_help $1)" -- $cur) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
}
# helper function completes supported bluealsa-agent status properties
_bluealsa_agent_status_properties() {
local properties=( Running SoftVolume Delay )
if [[ "$cur" == *,* ]]; then
local realcur prefix chosen remaining
realcur="${cur##*,}"
prefix="${cur%,*}"
IFS="," read -ra chosen <<< "${prefix}"
readarray -t remaining < <(printf '%s\n' "${properties[@]}" "${chosen[@]}" | sort | uniq -u)
if [[ ${#remaining[@]} -gt 0 ]]; then
readarray -t COMPREPLY < <(compgen -W "${remaining[*]}" -- "$realcur")
if [[ ${#COMPREPLY[@]} -eq 1 ]] ; then
COMPREPLY[0]="$prefix,${COMPREPLY[0]}"
fi
if [[ ${#remaining[@]} -gt 0 && "$cur" == "${COMPREPLY[0]}" ]] ; then
COMPREPLY=( "${COMPREPLY[0]}," )
fi
if [[ ${#remaining[@]} -gt 1 ]]; then
compopt -o nospace
fi
fi
else
readarray -t COMPREPLY < <(compgen -W "${properties[*]}" -- "$cur")
if [[ ${#COMPREPLY[@]} -eq 1 && "$cur" == "${COMPREPLY[0]}" ]]; then
COMPREPLY=("${COMPREPLY[0]},")
fi
compopt -o nospace
fi
}
# completion function for bluealsa-agent
_bluealsa_agent() {
local cur prev words cword split
_init_completion -s || return
case "$prev" in
"--dbus")
COMPREPLY=()
return
;;
"--mode")
COMPREPLY=( $(compgen -W "sink source" -- $cur) )
return
;;
"--profile")
COMPREPLY=( $(compgen -W "a2dp sco" -- $cur) )
return
;;
"--status")
if [[ "${words[cword]}" == "" ]] ; then
COMPREPLY=( "--status=" )
compopt -o nospace
else
_bluealsa_agent_status_properties
fi
return;
;;
esac
if [[ "$cur" == "-"* ]] ; then
COMPREPLY=( $(compgen -W "$(_parse_help $1)" -- $cur) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
COMPREPLY=( $(compgen -f $cur) )
fi
}
complete -F _bluealsa_autoconfig bluealsa-autoconfig
complete -F _bluealsa_agent bluealsa-agent