volumeControl.sh is now POSIX compliant with /bin/sh on its shebang

master
Meliurwen 3 years ago
parent 3aa60ab4d4
commit 2777961ee9
Signed by: meliurwen
GPG Key ID: 818A8B35E9F1CE10
  1. 43
      i3/.config/i3/scripts/volumeControl.sh

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/bin/sh
# You can call this script like this: # You can call this script like this:
# $ ./volumeControl.sh up # $ ./volumeControl.sh up
@ -10,54 +10,57 @@
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh # https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a # https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a
function get_volume { get_volume() {
amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1 amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
} }
function is_mute { is_mute() {
amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
} }
function is_mic_mute { is_mic_mute() {
amixer get Capture | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null amixer get Capture | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
} }
function draw_bar { draw_bar() {
percentual=$1 percentual=$1
slices=$2 slices=$2
lvl=$((percentual / slices)) lvl=$((percentual / slices))
empty=$(((100 / slices) - lvl)) empty_lvl=$(((100 / slices) - lvl))
n=0
lvl_bar="" lvl_bar=""
for X in $(seq "$lvl"); do while [ $n -lt $lvl ]; do
lvl_bar="$lvl_bar$(printf '\u2588')" lvl_bar="$lvl_bar"
n=$((n + 1))
done done
empty_bar="" n=0
for X in $(seq "$empty"); do while [ $n -lt $empty_lvl ]; do
empty_bar="$empty_bar$(printf '\u2591')" lvl_bar="$lvl_bar"
n=$((n + 1))
done done
echo "$lvl_bar$empty_bar" printf "%s" "$lvl_bar"
} }
function send_notification { send_notification() {
if [ $1 == "audio" ] ; then if [ "$1" = "audio" ] ; then
replace_id=2593 replace_id=2593
if is_mute ; then if is_mute ; then
notif_icon="audio-volume-muted-dark" notif_icon="audio-volume-muted-dark"
notif_text="Audio Muted" notif_text="Audio Muted"
else else
volume=$(get_volume) volume=$(get_volume)
if [ $volume -le 0 ] ; then if [ "$volume" -le 0 ] ; then
notif_icon="audio-volume-none-dark" notif_icon="audio-volume-none-dark"
elif [ $volume -le 30 ] ; then elif [ "$volume" -le 30 ] ; then
notif_icon="audio-volume-low-dark" notif_icon="audio-volume-low-dark"
elif [ $volume -le 85 ] ; then elif [ "$volume" -le 85 ] ; then
notif_icon="audio-volume-medium-dark" notif_icon="audio-volume-medium-dark"
elif [ $volume -le 100 ] ; then elif [ "$volume" -le 100 ] ; then
notif_icon="audio-volume-high-dark" notif_icon="audio-volume-high-dark"
else else
notif_icon="audio-volume-overamplified-dark" notif_icon="audio-volume-overamplified-dark"
fi fi
notif_text="$(draw_bar $volume 5)" notif_text="$(draw_bar "$volume" 5)"
fi fi
else else
replace_id=2594 replace_id=2594
@ -76,8 +79,8 @@ function send_notification {
case $1 in case $1 in
up) up)
# set the volume on (if it was muted) # set the volume on (if it was muted)
# and then up/down the volume of the 5%
amixer -D pulse set Master on > /dev/null amixer -D pulse set Master on > /dev/null
# up the volume (+ 5%)
amixer -D pulse sset Master 5%+ > /dev/null amixer -D pulse sset Master 5%+ > /dev/null
send_notification audio send_notification audio
;; ;;

Loading…
Cancel
Save