aboutsummaryrefslogtreecommitdiffstats
path: root/bin/set_volume
diff options
context:
space:
mode:
Diffstat (limited to 'bin/set_volume')
-rwxr-xr-xbin/set_volume56
1 files changed, 29 insertions, 27 deletions
diff --git a/bin/set_volume b/bin/set_volume
index de980e5..acd6396 100755
--- a/bin/set_volume
+++ b/bin/set_volume
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
-FUNCTIONS=$HOME/bin/functions.sh
-[ -e $FUNCTIONS ] || exit 1
-. $FUNCTIONS
+set -euo pipefail
state_muted="/tmp/$(whoami)/state_muted"
state_muted_headphone=""
@@ -14,10 +12,10 @@ card_icon="/usr/share/icons/gnome/48x48/devices/audio-speakers.png" # gnome-icon
function increase_volume()
{
- mute amixer $cardselector sset Master 5%+
+ amixer $cardselector sset Master 5%+ &>/dev/null
local state_master=$(amixer $cardselector sget Master |grep "%" | cut -d'%' -f1 | cut -d '[' -f2 | uniq)
#update pactl bluetooth audio to same level if present
- if [ $state_bt_headphone = "[on]" ];then
+ if [ "$state_bt_headphone" = "[on]" ]; then
pactl set-sink-volume $name_bt_headphone "$state_master%"
fi
print_volumes $state_master
@@ -25,10 +23,10 @@ function increase_volume()
function decrease_volume()
{
- mute amixer $cardselector sset Master 5%-
+ amixer $cardselector sset Master 5%- &>/dev/null
local state_master=$(amixer $cardselector sget Master |grep "%" | cut -d'%' -f1 | cut -d '[' -f2 | uniq)
#update pactl bluetooth audio to same level if present
- if [ $state_bt_headphone = "[on]" ];then
+ if [ "$state_bt_headphone" = "[on]" ];then
pactl set-sink-volume $name_bt_headphone "$state_master%"
fi
print_volumes $state_master
@@ -39,7 +37,7 @@ function print_volumes()
local state_master=$1
local state_headphone=$(amixer $cardselector sget Headphone |grep "%" | cut -d'%' -f1 | cut -d '[' -f2 | uniq)
local state_speaker=$(amixer $cardselector sget Speaker |grep "%" | cut -d'%' -f1 | cut -d '[' -f2 | uniq)
- if [ $state_bt_headphone = "[on]" ]; then
+ if [ "$state_bt_headphone" = "[on]" ]; then
send_notify "Master: $state_master% Headphone: $state_headphone% Speaker: $state_speaker% BT Headphone: $state_master%"
else
send_notify "Master: $state_master% Headphone: $state_headphone% Speaker: $state_speaker%"
@@ -53,50 +51,50 @@ function toggle_volume()
local state_speaker=$(amixer $cardselector sget Speaker | grep -o '\[o[n|f]*\]' | head -n 1)
case "$state_master" in
"[on]")
- mute amixer $cardselector sset Master mute
+ amixer $cardselector sset Master mute &>/dev/null
state_master="[off]"
# if headphones are off already, don't mute, instead save state to tmp file
if [ "$state_headphone" = "[off]" ];then
echo "headphone [off]" >> "$state_muted"
else
- mute amixer $cardselector sset Headphone mute
+ amixer $cardselector sset Headphone mute &>/dev/null
state_headphone="[off]"
fi
# if speakers are off already, don't mute, instead save state to tmp file
if [ "$state_speaker" = "[off]" ];then
echo "speaker [off]" >> "$state_muted"
else
- mute amixer $cardselector sset Speaker mute
+ amixer $cardselector sset Speaker mute &>/dev/null
state_speaker="[off]"
fi
# if present, also mute bluetooth headphone
- if [ $state_bt_headphone = "[on]" ]; then
+ if [ "$state_bt_headphone" = "[on]" ]; then
pactl set-sink-mute $name_bt_headphone 1
fi
;;
"[off]")
- mute amixer $cardselector sset Master unmute
+ amixer $cardselector sset Master unmute &>/dev/null
state_master="[on]"
# if headphones are meant to be off, don't unmute them again
if [ "$state_muted_headphone" != "[off]" ];then
- mute amixer $cardselector sset Headphone unmute
+ amixer $cardselector sset Headphone unmute &>/dev/null
state_headphone="[on]"
fi
# if headphones are meant to be off, don't unmute them again
if [ "$state_muted_speaker" != "[off]" ];then
- mute amixer $cardselector sset Speaker unmute
+ amixer $cardselector sset Speaker unmute &>/dev/null
state_speaker="[on]"
fi
# if present, also unmute bluetooth headphone
- if [ $state_bt_headphone = "[on]" ]; then
+ if [ "$state_bt_headphone" = "[on]" ]; then
pactl set-sink-mute $name_bt_headphone 0
fi
;;
esac
- if [ $state_bt_headphone = "[on]" ]; then
- send_notify "Master: $state_master \nHeadphone: $state_headphone \nSpeaker: $state_speaker\nBT Headphone: $state_master" 2000
+ if [ "$state_bt_headphone" = "[on]" ]; then
+ send_notify "Master: $state_master Headphone: $state_headphone Speaker: $state_speaker BT Headphone: $state_master" 2000
else
- send_notify "Master: $state_master \nHeadphone: $state_headphone \nSpeaker: $state_speaker" 2000
+ send_notify "Master: $state_master Headphone: $state_headphone Speaker: $state_speaker" 2000
fi
}
@@ -104,9 +102,9 @@ function send_notify()
{
# allow timeout to be set by 2nd argument
local timeout=1000
- if [ $2 -gt 0 ]; then
- timeout=$2
- fi
+# if [ $2 -gt 0 ]; then
+# timeout=$2
+# fi
notify-send -t $timeout \
-i /usr/share/icons/gnome/48x48/devices/audio-speakers.png \
"Volume" "$1"
@@ -121,16 +119,18 @@ if [ $HOSTNAME = "dvzrv" ];then
fi
case "$1" in
- increase)
+ "increase")
increase_volume
;;
- decrease)
+ "decrease")
decrease_volume
;;
- toggle)
+ "toggle")
if [ -f "$state_muted" ]; then
- state_muted_headphone=$(cat "$state_muted" | grep headphone | cut -d' ' -f2)
- state_muted_speaker=$(cat "$state_muted" | grep speaker | cut -d' ' -f2)
+ set +e
+ state_muted_speaker="$(cat "$state_muted" | grep speaker | cut -d' ' -f2)"
+ state_muted_headphone="$(cat "$state_muted" | grep headphone | cut -d' ' -f2)"
+ set -e
rm "$state_muted"
else
touch "$state_muted"
@@ -140,3 +140,5 @@ case "$1" in
*)
;;
esac
+
+exit 0