diff --git a/.bin/setaudio b/.bin/setaudio index f68a6ef..2820619 100755 --- a/.bin/setaudio +++ b/.bin/setaudio @@ -1,9 +1,9 @@ #!/bin/ksh -# set the sound device via argument +# set the sound device via argument (if you put something stupid her, so be it...) [ ! -z $1 ] && sndioctl -q server.device=$1 -# we need if a few times, and caching is faster +# we need it a few times, and caching is faster DUMP=$(dmesg) # save the current active sound device @@ -12,8 +12,11 @@ _cur=$(sndioctl -n server.device) # starting from dev 4, you need to cd /dev && sh MAKEDEV audioX for i in 0 1 2 3 4 5 6 do - # find audio line - _input="$(echo "$DUMP" | grep -E "^audio$i\ at.*" | tail -1)" + # 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 # take the number from audioX, then grep for what's attached to find # the last description for this device (usb devices may change order @@ -23,7 +26,7 @@ do _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. + # Once we walked to the first non-existing device, we stop. [ -z $_number ] && exit 0 # Show the device list and mark the current one