-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauctl
More file actions
executable file
·234 lines (201 loc) · 4.31 KB
/
Copy pathauctl
File metadata and controls
executable file
·234 lines (201 loc) · 4.31 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env bash
# auctl - PipeWire audio helper (wpctl + fzf)
#
# Commands:
# auctl output | out Pick output device (sink)
# auctl input | in Pick input device (source)
#
# auctl up [(-i|--input|in)] [STEP]
# Volume +STEP% (default 5) on output (default) or input.
#
# auctl down [(-i|--input|in)] [STEP]
# Volume -STEP% (default 5) on output (default) or input.
#
# auctl mute [(-i|--input|in)] [0|1|toggle]
# Mute/unmute output (default) or input. Default action: toggle.
#
# auctl volume [(-i|--input|in)] [VAL]
# Show or set volume for output (default) or input.
# VAL examples: 50 50% 0.5
#
# auctl status
# Show wpctl status.
#
# auctl help
# Show this help.
usage() {
cat <<'EOF'
auctl - PipeWire audio helper (wpctl + fzf)
Usage:
auctl output | out
Pick output device (sink).
auctl input | in
Pick input device (source).
auctl up [(-i|--input|in)] [STEP]
Volume +STEP% (default 5) on output (default) or input.
auctl down [(-i|--input|in)] [STEP]
Volume -STEP% (default 5) on output (default) or input.
auctl mute [(-i|--input|in)] [0|1|toggle]
Mute/unmute output (default) or input. Default action: toggle.
auctl volume [(-i|--input|in)] [VAL]
Show or set volume for output (default) or input.
VAL examples: 50 50% 0.5
auctl status
Show wpctl status.
auctl help
Show this help.
EOF
exit 1
}
# kind: "output" or "input"
pick_node() {
local kind="$1"
local header_from header_to
case "$kind" in
output | out)
header_from="Sinks:"
header_to="Sink endpoints:"
;;
input | in)
header_from="Sources:"
header_to="Source endpoints:"
;;
*)
echo "pick_node: invalid kind '$kind'" >&2
exit 1
;;
esac
local block selection id
block="$(
wpctl status |
awk "/$header_from/{flag=1;next}/$header_to/{flag=0}flag"
)"
selection="$(
printf '%s\n' "$block" |
grep -E '[0-9]+\.' |
sed 's/^[[:space:]]*//'
)"
[ -z "$selection" ] && {
echo "auctl: no $kind entries found" >&2
exit 1
}
selection="$(
printf '%s\n' "$selection" |
fzf --prompt="Select $kind > " --ansi
)" || exit 0
id="$(sed -E 's/^[^0-9]*([0-9]+)\..*/\1/' <<<"$selection")"
[ -z "$id" ] && {
echo "auctl: failed to parse $kind id from selection" >&2
exit 1
}
printf '%s\n' "$id"
}
default_token() {
case "$1" in
input | in) echo "@DEFAULT_AUDIO_SOURCE@" ;;
*) echo "@DEFAULT_AUDIO_SINK@" ;;
esac
}
normalize_volume_arg() {
local v="$1"
case "$v" in
*% | 0.* | 1.*)
echo "$v"
;;
*)
# plain number -> percent
echo "${v}%"
;;
esac
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
set -euo pipefail
cmd="${1:-help}"
shift || true
case "$cmd" in
output | out)
id="$(pick_node output)"
wpctl set-default "$id"
;;
input | in)
id="$(pick_node input)"
wpctl set-default "$id"
;;
up)
target="out"
case "${1-}" in
-i | --input | in)
target="in"
shift
;;
esac
step="${1:-5}"
tok="$(default_token "$target")"
wpctl set-volume "$tok" "${step}%+"
;;
down)
target="out"
case "${1-}" in
-i | --input | in)
target="in"
shift
;;
esac
step="${1:-5}"
tok="$(default_token "$target")"
wpctl set-volume "$tok" "${step}%-"
;;
mute)
target="out"
case "${1-}" in
-i | --input | in)
target="in"
shift
;;
esac
action="${1:-toggle}"
tok="$(default_token "$target")"
wpctl set-mute "$tok" "$action"
;;
unmute)
target="out"
case "${1-}" in
-i | --input | in)
target="in"
shift
;;
esac
action="${1:-0}"
tok="$(default_token "$target")"
wpctl set-mute "$tok" "$action"
;;
volume | vol)
target="out"
case "${1-}" in
-i | --input | in)
target="in"
shift
;;
esac
tok="$(default_token "$target")"
if [ $# -gt 0 ]; then
val="$(normalize_volume_arg "$1")"
wpctl set-volume "$tok" "$val"
else
wpctl get-volume "$tok"
fi
;;
status)
wpctl status
;;
help | --help | -h)
usage
;;
*)
echo "auctl: unknown command: $cmd" >&2
usage
;;
esac
fi
alias mute='auctl mute'
alias vol='auctl volume'