music-general-control.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. display_help(){
  4. echo "Usage: ${0##*/} [flag/s] [file/s]"
  5. echo "Flags:"
  6. echo -e "\t -h --Display help message"
  7. exit 2
  8. }
  9. [[ $# -lt 1 ]] && display_help
  10. song_next(){
  11. mpc next || cmus-remote --next || mocp --next
  12. }
  13. song_prev(){
  14. mpc prev || cmus-remote --prev || mocp --prev
  15. }
  16. song_toggle(){
  17. mpc toggle || cmus-remote --pause || mocp --toggle-pause
  18. }
  19. song_volume(){
  20. mpc volume "$1" || cmus-remote --volume "$1" || mocp --volume "$1"
  21. }
  22. song_stop(){
  23. mpc stop || cmus-remote --stop || mocp --stop
  24. }
  25. show_notification(){
  26. cover_size="${1:-200}"
  27. if pidof mpd; then
  28. mpd-notify.sh "$cover_size"
  29. elif pidof cmus; then
  30. cmus-notify.sh "$cover_size"
  31. elif pidof mocp; then
  32. mocp-notify.sh "$cover_size"
  33. fi
  34. }
  35. while getopts 'nptsv:h' opt; do
  36. case "$opt" in
  37. n) song_next ;;
  38. p) song_prev ;;
  39. t) song_toggle ;;
  40. v) song_volume "$OPTARG" ;;
  41. s) song_stop;;
  42. h|\?|:|*) display_help ;;
  43. esac
  44. done
  45. show_notification 200