dotfiles/.bin/OLD/setaudio

40 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-04-10 13:00:38 +02:00
#!/bin/ksh
2023-04-09 20:37:05 +02:00
2023-04-10 13:48:58 +02:00
# set the sound device via argument (if you put something stupid her, so be it...)
2023-04-10 13:00:38 +02:00
[ ! -z $1 ] && sndioctl -q server.device=$1
2023-04-09 20:37:05 +02:00
2023-04-10 13:48:58 +02:00
# we need it a few times, and caching is faster
2023-04-10 13:00:38 +02:00
DUMP=$(dmesg)
2023-04-10 13:26:33 +02:00
# save the current active sound device
2023-04-10 13:00:38 +02:00
_cur=$(sndioctl -n server.device)
2023-04-09 20:37:05 +02:00
2023-04-10 13:26:33 +02:00
# starting from dev 4, you need to cd /dev && sh MAKEDEV audioX
for i in 0 1 2 3 4 5 6
do
2023-04-10 13:48:58 +02:00
# find audio attach and detach lines
_input="$(echo "$DUMP" | grep -E "^audio$i\ at.*|^audio$i detached" | tail -n 1)"
# if the last match is a detached line, stop here
echo "$_input" | grep -q "detached" && continue
2023-04-10 13:26:33 +02:00
# take the number from audioX, then grep for what's attached to find
# the last description for this device (usb devices may change order
# during runtime)
_type=$(echo "$_input" | cut -d" " -f3)
_number=$(echo "$_input" | cut -d" " -f1 | sed 's/[a-z]//g')
2023-04-10 13:00:38 +02:00
_desc=$(echo "$DUMP" | grep -E "^$_type at.*" | tail -1 | cut -d'"' -f2)
2023-04-10 13:48:58 +02:00
# Once we walked to the first non-existing device, we stop.
2023-04-10 13:26:33 +02:00
[ -z $_number ] && exit 0
# Show the device list and mark the current one
2023-04-10 13:00:38 +02:00
if [ $_cur -eq $_number ]
then
2023-04-10 13:26:33 +02:00
echo "> $_number: $_desc"
2023-04-10 13:00:38 +02:00
else
2023-04-10 13:26:33 +02:00
echo " $_number: $_desc"
2023-04-10 13:00:38 +02:00
fi
done