123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. . $(ffoom path)
  3. ffoo import pretty
  4. usage() {
  5. usage_is "up" \
  6. "down" \
  7. "flip" \
  8. "mute" \
  9. "unmute"
  10. }
  11. sound_is_muted() {
  12. #
  13. # At least one playback channel is muted
  14. #
  15. local master_status="$(amixer get Master)"
  16. echo "$master_status" \
  17. | grep "Playback channels" \
  18. | sed -e 's/.*: //; s/ - /\n/' \
  19. | while read chname
  20. do
  21. grep -e "^ *$chname" <<<"$master_status"
  22. done \
  23. | grep -qse '\[off\]$'
  24. }
  25. do_down() {
  26. #
  27. # turn volume down
  28. #
  29. amixer -q sset Master 5%-
  30. }
  31. do_flip() {
  32. #
  33. # mute or unmute
  34. #
  35. if sound_is_muted;
  36. then
  37. amixer -q sset Master unmute;
  38. else
  39. amixer -q sset Master mute;
  40. fi
  41. }
  42. do_mute() {
  43. #
  44. # mute
  45. #
  46. amixer -q sset Master mute
  47. }
  48. do_up() {
  49. #
  50. # turn volume up
  51. #
  52. amixer -q sset Master 5%+
  53. }
  54. do_unmute() {
  55. #
  56. # mute
  57. #
  58. amixer -q sset Master unmute
  59. }
  60. action=
  61. while true; do case "$1" in
  62. up) action=up; shift ;;
  63. down) action=down; shift ;;
  64. flip) action=flip; shift ;;
  65. mute) action=mute; shift ;;
  66. unmute) action=unmute; shift ;;
  67. "") break ;;
  68. *) usage ;;
  69. esac done
  70. debug "\$@='$@'"
  71. debug -v action
  72. case $action in
  73. up|down|flip|mute|unmute) do_$action ;;
  74. *) usage ;;
  75. esac