Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Защита от повторного запуска скрипта
- [ `pgrep -c volume.sh` -gt 1 ] && echo "no way" && exit 1
- # узнаем текущую громкость
- get_volume()
- {
- amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
- }
- # Проверяем отключен ли звук
- is_mute()
- {
- amixer get Master | grep '%' | grep -oE '[^ ]+$' | head -n 1
- }
- send_notification()
- {
- if [[ "`is_mute`" = "[on]" ]] ;
- then
- icon_name="audio-volume-muted"
- bar=" Без звука"
- else
- display_volume=`get_volume`
- count=21
- st=$(($display_volume / 5))
- en=$(($count - $st))
- if [ $en -ge 21 ]; then
- en=20
- st=0
- fi
- # Прогресбар
- # https://en.wikipedia.org/wiki/Box-drawing_character
- pr1=$(seq -s "█" $st | sed 's/[0-9]//g')
- pr2=$(seq -s "░" $en | sed 's/[0-9]//g')
- bar="$pr1$pr2"
- # Иконка
- if [ $display_volume -le 25 ]; then
- icon_name="audio-volume-low"
- elif [ $display_volume -le 75 ]; then
- icon_name="audio-volume-medium"
- else
- icon_name="audio-volume-high"
- fi
- # Проценты
- if [ $display_volume -lt 100 ] ; then
- parsent="$display_volume%"
- else
- parsent="$display_volume"
- fi
- fi
- # Отправляем уведомление
- dunstify -i "$icon_name" -t 1500 -r 2593 -u normal "$bar $parsent"
- }
- case $1 in
- "up")
- amixer set Master 1%+
- send_notification
- ;;
- "down")
- amixer set Master 1%-
- send_notification
- ;;
- "mute")
- amixer set Master toggle
- if [[ "`is_mute`" = "[on]" ]] ;
- then
- pnmixer &
- fi
- send_notification
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement