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:
# $ ./volumeControl.sh up
@ -10,54 +10,57 @@
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# 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
}
function is_mute {
is_mute() {
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
}
function draw_bar {
draw_bar() {
percentual=$1
slices=$2
lvl=$((percentual / slices))
empty=$(((100 / slices) - lvl))
empty_lvl=$(((100 / slices) - lvl))
n=0
lvl_bar=""
for X in $(seq "$lvl"); do
lvl_bar="$lvl_bar$(printf '\u2588')"
while [ $n -lt $lvl ]; do
lvl_bar="$lvl_bar"
n=$((n + 1))
done
empty_bar=""
for X in $(seq "$empty"); do
empty_bar="$empty_bar$(printf '\u2591')"
n=0
while [ $n -lt $empty_lvl ]; do
lvl_bar="$lvl_bar"
n=$((n + 1))
done
echo "$lvl_bar$empty_bar"
printf "%s" "$lvl_bar"
}
function send_notification {
if [ $1 == "audio" ] ; then
send_notification() {
if [ "$1" = "audio" ] ; then
replace_id=2593
if is_mute ; then
notif_icon="audio-volume-muted-dark"
notif_text="Audio Muted"
else
volume=$(get_volume)
if [ $volume -le 0 ] ; then
if [ "$volume" -le 0 ] ; then
notif_icon="audio-volume-none-dark"
elif [ $volume -le 30 ] ; then
elif [ "$volume" -le 30 ] ; then
notif_icon="audio-volume-low-dark"
elif [ $volume -le 85 ] ; then
elif [ "$volume" -le 85 ] ; then
notif_icon="audio-volume-medium-dark"
elif [ $volume -le 100 ] ; then
elif [ "$volume" -le 100 ] ; then
notif_icon="audio-volume-high-dark"
else
notif_icon="audio-volume-overamplified-dark"
fi
notif_text="$(draw_bar $volume 5)"
notif_text="$(draw_bar "$volume" 5)"
fi
else
replace_id=2594
@ -76,8 +79,8 @@ function send_notification {
case $1 in
up)
# 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
# up the volume (+ 5%)
amixer -D pulse sset Master 5%+ > /dev/null
send_notification audio
;;

Loading…
Cancel
Save