Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

  1. #!/bin/bash
  2. # pacontrol.sh
  3. #
  4. # This script changes the volume of the current audio source based on a set interval
  5. function send_notification {
  6. if [ "$2" = "yes" ]; then
  7. icon="婢"
  8. dunstify -t 1000 -r 53 -a "蓼 Volume" "$icon MUTED"
  9. return
  10. else
  11. if [ "$1" -lt "20" ]; then
  12. icon="奄"
  13. else
  14. if [ "$1" -lt "60" ]; then
  15. icon="奔"
  16. else
  17. icon="墳"
  18. fi
  19. fi
  20. fi
  21. bar=$(seq -s "─" $(($1/5)) | sed 's/[0-9]//g')
  22. empty=$(seq -s " ⁠" $((20 - $1/5)) | sed 's/[0-9]//g')
  23. dunstify -t 1000 -r 53 -a "蓼 Volume" "$icon $bar$empty"
  24. }
  25. usage() {
  26. echo "Usage: pacontrol.sh [up|down|toggle-mute]"
  27. }
  28. vol_interval=5
  29. sinks=$(pactl list short sinks | cut -c 1)
  30. latest_sink=${sinks[*]: -1}
  31. SINK=$(pactl list short sinks | grep -n RUNNING | cut -d":" -f1)
  32. if [ "$SINK" = "" ]; then
  33. SINK=1
  34. fi
  35. NOW=$( pactl list sinks | grep '^[[:space:]]Volume:' | head -n $SINK | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' )
  36. MUTE=$(pactl list sinks | grep '^[[:space:]]Mute:'| head -n $SINK | tail -n 1 | awk -F ":" '{print $2}'| xargs)
  37. case $1 in
  38. "up")
  39. pactl set-sink-mute $latest_sink 0
  40. if [ "$NOW" -lt "100" ]; then
  41. pactl set-sink-volume $latest_sink +$vol_interval%
  42. else
  43. pactl set-sink-volume $latest_sink 100%
  44. fi
  45. ;;
  46. "down")
  47. pactl set-sink-volume $latest_sink -$vol_interval%
  48. ;;
  49. "toggle-mute")
  50. pactl set-sink-mute $latest_sink toggle
  51. ;;
  52. "open-mute")
  53. pactl set-sink-mute $latest_sink 1
  54. ;;
  55. "close-mute")
  56. pactl set-sink-mute $latest_sink 0
  57. ;;
  58. *) usage ;;
  59. esac
  60. NOW=$( pactl list sinks | grep '^[[:space:]]Volume:' | head -n $SINK | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' )
  61. MUTE=$(pactl list sinks | grep '^[[:space:]]Mute:'| head -n $SINK | tail -n 1 | awk -F ":" '{print $2}'| xargs)
  62. kill -48 $(pidof dwmblocks)
  63. send_notification $NOW $MUTE