Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 131 lines (118 sloc) 4.696 kb
8c5e148 Daniel Wallace add zsh completion
gtmanfred authored
1 #compdef ponymix
2
3 local -a _commands _movesink
4 local state line curcontext="$curcontext"
5 typeset -U _commands
6 _common_command(){
7 _commands+=(
8 'list:list available dsevices'
9 'list-short:list available devices, short form'
10 'list-cards:list available cards'
11 'list-cards-short:list available cards, short form'
12 'get-volume:get volume for device'
13 'set-volume:set volume for device:integer'
14 'get-balance:get balance for device'
15 'set-balance:set balance for device:integer'
16 'adj-balance:increase or decrease balance for device:integer'
17 'increase:increase volume:integer'
18 'decrease:decrease volume:integer'
19 'mute:mute device'
20 'kill:kill device'
21 'unmute:unmute device'
22 'toggle:toggle mute'
23 'is-muted:check if muted'
24 )
25 cmd="${${_commands[(r)$words[$((CURRENT - 1))]:*]%%:*}}"
26 if (( ! $#cmd )); then
27 _describe commands _commands;
28 else
29 if (( $#cmd )) && [[ "$cmd" == set-* || "$cmd" == adj-* ]]; then
30 _message "number for $cmd"
31 else
32 _message "no more options"
33 fi
34 fi
35 }
36
37 _devices(){
38 local -a _sourcelist _sinklist _inputlist
39 for f in ${(f)"$(_call_program sink_tag "$service --sink list-short")"}; do
40 _sinklist+=(${${(ps:\t:)f}[3]}:${(q)${(ps:\t:)f}[4]})
41 done
42 for f in ${(f)"$(_call_program source_tag "$service --source list-short")"}; do
43 _sourcelist+=(${${(ps:\t:)f}[3]}:${(q)${(ps:\t:)f}[4]})
44 done
45 for f in ${(f)"$(_call_program sink_input_tag "$service --sink-input list-short")"}; do
46 _inputlist+=(${${(ps:\t:)f}[2]}:${(q)${(ps:\t:)f}[4]})
47 done
48
49
50 if [[ $words[(r)*sink-input*] == *sink-input ]]; then
51 _describe "sink inputs" _inputlist
52 elif [[ $words[(r)*(sink|output)*] == *(sink|output) ]]; then
53 _describe "sink" _sinklist
54 elif [[ $words[(r)*(source|input)*] == *(source|input) ]]; then
55 _describe "source" _sourcelist
56 else
57 _alternative \
58 "source_tag:source list:((${(q)_sourcelist[@]}))" \
59 "sink_tag:sink:((${(q)_sinklist[@]}))" \
60 "sink_input_tag:sink_input:((${(q)_inputlist[@]}))"
61 fi
62 }
63
64 _set_profiles(){
65 local -a _profileslist
66 local _card
67
68 _card=$words[$(($words[(i)-(c|-card)] + 1))]
69 _profileslist=(${${(f)"$(_call_program profiles_tag "$service --card $_card list-profiles-short")"}//:/\:})
70 compadd "$@" - "$_profileslist[@]"
71 }
72
73 _cards(){
74 local -a _cardlist
75 _cardlist=(${(f)"$(_call_program card_tag "$service list-cards-short")"})
76 _describe 'card list' _cardlist
77 }
78 _card_commands=(
79 'list-profiles:list available profiles for a card'
80 'list-profiles-short:list available profiles for a card, short form'
81 'get-profile:get active profile for card'
82 'set-profile:set profile for a card:_set_profiles'
83 )
84
85 if [[ -n $words[(r)*(sink-input|source-output)] ]]; then
86 _commands+=(
87 'move:Move device'
88 )
89 fi
90
91 [[ $words[(r)-(d|-device)] == -(d|-device) ]] && _commands+=(
92 'defaults:list default devices (default command)'
93 'set-default:set default devices')
94
95 [[ $words[(r)-(c|-card)] == -(c|-card) ]] && _commands+=( "$_card_commands[@]" )
96
97 if [[ $words[$((CURRENT - 1))] == move ]]; then
98 for f in ${(f)"$(_call_program sink_tag "$service --sink list-short")"}; do
99 _movesink+=(${${(ps:\t:)f}[3]}:${(q)${(ps:\t:)f}[4]})
100 done
101 _describe "sink" _movesink
102 elif [[ $words[$((CURRENT - 1))] == set-profile ]]; then
103 _set_profiles
104 else
105 _arguments -C \
106 '::common commands:_common_command' \
107 '(-c --card -d --device)'{-d,--device}'[Select Device]:devices:_devices' \
108 - '(help)' \
109 {-h,--help}'[display this help and exit]' \
30cd588 Dave Reisner add version function, wire it up from the makefile
authored
110 - '(version)' \
111 {-V,--version}'[display program version and exit]' \
8c5e148 Daniel Wallace add zsh completion
gtmanfred authored
112 - '(sink)' \
113 '--sink[alias to type sink]' \
114 '--output[alias to type sink]' \
115 {-t,--devtype}'[Device Type]: :(sink output)' \
116 - '(source)' \
117 '--source[alias to type source]' \
118 '--input[alias to type source]' \
119 {-t,--devtype}'[Device Type]: :(source input)' \
120 - '(sink-input)' \
121 '--sink-input[alias to type sink-input]' \
122 {-t,--devtype}'[Device Type]: :(sink-input)' \
123 - '(source-output)' \
124 {-t,--devtype}'[Device Type]:device types:(source-output)' \
be87702 Jordan Beaver spelling correction source-output
gehidore authored
125 '--source-output[alias to type source-output]' \
8c5e148 Daniel Wallace add zsh completion
gtmanfred authored
126 - '(card)' \
127 '(-d --device)'{-c,--card}'[target card]:Cards:_cards:Card Commands:((${(q)_card_commands}))'
128 fi
129
130 #vim: set ft=zsh sw=4 ts=4 noet
Something went wrong with that request. Please try again.