diff options
Diffstat (limited to '.local/bin')
-rwxr-xr-x | .local/bin/pa_control | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/.local/bin/pa_control b/.local/bin/pa_control index 9a53b9a..b3d566a 100755 --- a/.local/bin/pa_control +++ b/.local/bin/pa_control @@ -3,11 +3,9 @@ # This script is just used to get the current PA sink, # and to change to the 'next' sink. Using only 'pactl'. -default_sink= -default_sink_nickname= get_default_sink (){ - default_sink="$(pactl info | grep Sink | awk '{print $3}')" + echo "$(pactl info | grep Sink | awk '{print $3}')" } get_default_sink_nickname (){ @@ -15,6 +13,8 @@ get_default_sink_nickname (){ | grep -e Name -e alsa.card_name\ | sed -e 's/^\ *//' -e 's/\ *$//')" + default_sink="$(get_default_sink)" + found_default_sink="0" while IFS= read line; do @@ -27,13 +27,13 @@ get_default_sink_nickname (){ # If fond default_sink, get and set the nickname, then exit. - if [ $found_default_sink = "1" ]; then - default_sink_nickname="$line" + if [ "$found_default_sink" = "1" ]; then + echo "$line" break; fi # If current line is the default sink, set a flag. - if [ $default_sink = "$line" ]; then + if [ "$default_sink" = "$line" ]; then found_default_sink="1" fi done <<EOF @@ -49,55 +49,52 @@ set_next_sink (){ | sed -e 's/^\ *//' -e 's/\ *$//'\ | cut -d' ' -f2)" + default_sink="$(get_default_sink)" + default_sink_nickname="$(get_default_sink_nickname)" + # Some flags because I don't know a better way to do this, lol. found_default_sink="0" setted_after_finding_default_sink="0" first_found_sink="0" while IFS= read line; do - if [ $found_default_sink = "1" ]; then + # For some reason, when expanding, the first entry of 'sink_list' contains white spaces... + line="$(echo $line | sed -e 's/\ //')" + + if [ "$found_default_sink" = "1" ]; then pactl set-default-sink $line setted_after_finding_default_sink="1" + break; fi - if [ $default_sink = $line ]; then + if [ "$default_sink" = "$line" ]; then found_default_sink="1" - else - # In case the first line is not he default sink, - # store the first found sink in case the default sink, - # is at the end of the variable (in which case the while loop - # exits and we no longer know which one is next [next would be the first - # line ;) ]) - if [ $first_found_sink = "0" ]; then - first_found_sink="$line" - fi + fi + + # In case the first line is not he default sink, + # store the first found sink in case the default sink, + # is at the end of the variable (in which case the while loop + # exits and we no longer know which one is next [next would be the first + # line ;) ]) + if [ "$first_found_sink" = "0" ]; then + first_found_sink="$line" fi done <<EOF $sink_list EOF # If the next sink wasn't set after finding the default sink, it means # the next sink is actually the first sink, so, set it here - if [ $setted_after_finding_default_sink = "0" ]; then + if [ "$setted_after_finding_default_sink" = "0" ]; then pactl set-default-sink $first_found_sink fi } case "$1" in get-sink) - get_default_sink - get_default_sink_nickname - - notify-send "Current sink" "$default_sink_nickname" + notify-send "Current sink" "$(get_default_sink_nickname)" ;; next-sink) - get_default_sink - get_default_sink_nickname - set_next_sink - - get_default_sink - get_default_sink_nickname - - notify-send "Changed to sink" "$(echo $default_sink_nickname)" + notify-send "Changed to sink" "$(get_default_sink_nickname)" ;; esac |