dotfiles

Torpy's handcrafted dootfiles.
Log | Files | Refs | README

sb-volume (920B)


      1 #!/bin/sh
      2 
      3 # Prints the current volume or M if muted.
      4 
      5 case $BLOCK_BUTTON in
      6 	1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" ;;
      7 	2) wpctl set-mute @DEFAULT_SINK@ toggle ;;
      8 	4) wpctl set-volume @DEFAULT_SINK@ 1%+ ;;
      9 	5) wpctl set-volume @DEFAULT_SINK@ 1%- ;;
     10 	3) notify-send "Volume module" "\- Shows volume V, M if muted.
     11 - Middle click to mute.
     12 - Scroll to change." ;;
     13 	6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
     14 esac
     15 
     16 vol="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)"
     17 
     18 # If muted, print M and exit.
     19 [ "$vol" != "${vol%\[MUTED\]}" ] && echo 'M ' && exit
     20 
     21 vol="${vol#Volume: }"
     22 
     23 split() {
     24 	# For ommiting the . without calling and external program.
     25 	IFS=$2
     26 	set -- $1
     27 	printf '%s' "$@"
     28 }
     29 
     30 vol="$(printf "%.0f" "$(split "$vol" ".")")"
     31 
     32 case 1 in
     33 	$((vol >= 70)) ) icon="V" ;;
     34 	$((vol >= 30)) ) icon="V" ;;
     35 	$((vol >= 1)) ) icon="V" ;;
     36 	* ) echo M && exit ;;
     37 esac
     38 
     39 echo "$icon $vol%"