dwmblocks/blocks/volume.sh

42 lines
1.2 KiB
Bash
Raw Normal View History

2020-07-18 12:00:48 +00:00
#!/bin/sh
2020-11-23 06:12:13 +00:00
pacmd list-sinks |
2020-12-27 15:28:23 +00:00
awk '
BEGIN {
ICONsn = "\x0c\x0b" # headphone unplugged, not muted
ICONsm = "\x0d\x0b" # headphone unplugged, muted
ICONhn = "\x0c\x0b" # headphone plugged in, not muted
ICONhm = "\x0d\x0b" # headphone plugged in, muted
}
2020-12-14 09:33:33 +00:00
{
if (f) {
if ($1 == "index:") {
exit
}
if ($1 == "muted:" && $2 == "yes") {
m = 1
} else if ($1 == "volume:") {
if ($3 == $10) {
vb = $5
} else {
vl = $5
vr = $12
}
} else if ($1 == "active" && $2 == "port:" && $3 ~ /headphone/) {
h = 1
}
} else if ($1 == "*" && $2 == "index:") {
f = 1
2020-11-23 06:12:13 +00:00
}
}
END {
2020-12-14 09:33:33 +00:00
if (f) {
2020-12-27 15:28:23 +00:00
printf "%s", h ? (m ? ICONhm : ICONhn) : (m ? ICONsm : ICONsn)
2020-12-14 09:33:33 +00:00
if (vb) {
print vb
} else {
printf "L%s R%s\n", vl, vr
}
2020-11-23 06:12:13 +00:00
}
}
'