blob: 3726f70d609e60117b59c0164d2e6668b8596f4a (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/bin/sh
# cycle between wireplumber(pipewire) audio sinks
parse_sinks()
{
isaudio=
isadsink=
while read -r line
do
case "$line" in
Audio)
isaudio=true
;;
├─\ Sinks:)
[ "$isaudio" = true ] &&
isadsink=true
;;
├─*:)
[ "$isadsink" = true ] &&
break
;;
*)
# skip if not inside audio sink
[ "$isadsink" != true ] &&
continue
# skip "blank" lines
[ -z "${line#│}" ] &&
continue
# clean up input
line="${line#│ }"
line="${line%%.*}"
sinks="${sinks}${line}:"
;;
esac
done
printf "%s" "${sinks%:}"
unset isaudio isadsink
}
cycle_sink()
{
read -r sinks
default_sink=
next_sink=
IFS=:
for sink in $sinks
do
case "$sink" in
\**)
default_sink="${sink##* }"
;;
*)
[ -z "$default_sink" ] &&
continue
next_sink="${sink##* }"
break
;;
esac
done
# if default sink is last one use first sink
if [ -z "$next_sink" ]
then
next_sink="${sinks%%:*}"
next_sink="${next_sink##* }"
fi
[ "$next_sink" != "$default_sink" ] &&
wpctl set-default "$next_sink"
}
wpctl status | parse_sinks | cycle_sink
|