From b08173cd34eddf7e01c68daa5d3ca9d38ecc7663 Mon Sep 17 00:00:00 2001 From: c0dev0id Date: Mon, 10 Apr 2023 13:26:33 +0200 Subject: [PATCH] Update 2023-04-10 13:26 OpenBSD/amd64 --- .bin/setaudio | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/.bin/setaudio b/.bin/setaudio index bf40adc..f68a6ef 100755 --- a/.bin/setaudio +++ b/.bin/setaudio @@ -1,25 +1,36 @@ #!/bin/ksh +# set the sound device via argument [ ! -z $1 ] && sndioctl -q server.device=$1 +# we need if a few times, and caching is faster DUMP=$(dmesg) + +# save the current active sound device _cur=$(sndioctl -n server.device) -examine() { - _type=$(echo "$1" | cut -d" " -f3) - _number=$(echo "$1" | cut -d" " -f1 | sed 's/[a-z]//g') - _desc=$(echo "$DUMP" | grep -E "^$_type at.*" | tail -1 | cut -d'"' -f2) - [ -z $_number ] && return - - if [ $_cur -eq $_number ] - then - [ ! -z $_number ] && echo "> $_number: $_desc" - else - [ ! -z $_number ] && echo " $_number: $_desc" - fi -} - +# starting from dev 4, you need to cd /dev && sh MAKEDEV audioX for i in 0 1 2 3 4 5 6 do - examine "$(echo "$DUMP" | grep -E "^audio$i\ at.*" | tail -1)" + # find audio line + _input="$(echo "$DUMP" | grep -E "^audio$i\ at.*" | tail -1)" + + # 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') + _desc=$(echo "$DUMP" | grep -E "^$_type at.*" | tail -1 | cut -d'"' -f2) + + # Once we walked to the first non-existing device, we can stop. + [ -z $_number ] && exit 0 + + # Show the device list and mark the current one + if [ $_cur -eq $_number ] + then + echo "> $_number: $_desc" + else + echo " $_number: $_desc" + fi done