Advertisement
pavver

volume.sh

Jun 10th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.87 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Защита от повторного запуска скрипта
  4. [ `pgrep -c volume.sh` -gt 1 ] && echo "no way" && exit 1
  5.  
  6. # узнаем текущую громкость
  7. get_volume()
  8. {
  9.     amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
  10. }
  11.  
  12. # Проверяем отключен ли звук
  13. is_mute()
  14. {
  15.     amixer get Master | grep '%' | grep -oE '[^ ]+$' | head -n 1
  16. }
  17.  
  18. send_notification()
  19. {
  20.     if [[ "`is_mute`" = "[on]" ]] ;
  21.     then
  22.         icon_name="audio-volume-muted"
  23.         bar="      Без звука"
  24.     else
  25.         display_volume=`get_volume`
  26.         count=21
  27.         st=$(($display_volume / 5))
  28.         en=$(($count - $st))
  29.        
  30.         if [ $en -ge 21 ]; then
  31.             en=20
  32.             st=0
  33.         fi
  34.  
  35.         # Прогресбар
  36.         # https://en.wikipedia.org/wiki/Box-drawing_character
  37.         pr1=$(seq -s "█" $st | sed 's/[0-9]//g')
  38.         pr2=$(seq -s "░" $en | sed 's/[0-9]//g')
  39.         bar="$pr1$pr2"
  40.        
  41.         # Иконка
  42.         if [ $display_volume -le 25 ]; then
  43.             icon_name="audio-volume-low"
  44.         elif [ $display_volume -le 75 ]; then
  45.             icon_name="audio-volume-medium"
  46.         else
  47.             icon_name="audio-volume-high"
  48.         fi
  49.  
  50.         # Проценты
  51.         if [ $display_volume -lt 100 ] ; then
  52.             parsent="$display_volume%"
  53.         else
  54.             parsent="$display_volume"
  55.         fi
  56.     fi
  57.    
  58.     # Отправляем уведомление
  59.     dunstify -i "$icon_name" -t 1500 -r 2593 -u normal "$bar $parsent"
  60. }
  61.  
  62. case $1 in
  63.     "up")
  64.         amixer set Master 1%+
  65.         send_notification
  66.     ;;
  67.     "down")
  68.         amixer set Master 1%-
  69.         send_notification
  70.     ;;
  71.     "mute")
  72.         amixer set Master toggle
  73.         if [[ "`is_mute`" = "[on]" ]] ;
  74.         then
  75.             pnmixer &
  76.         fi
  77.         send_notification
  78.     ;;
  79. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement