mpd 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. DIR="$HOME/.config/bspwm"
  3. rofi_command="rofi -theme $DIR/rofi/themes/mpd.rasi"
  4. # Gets the current status of mpd (for us to parse it later on)
  5. status="$(mpc status)"
  6. # Defines the Play / Pause option content
  7. if [[ $status == *"[playing]"* ]]; then
  8. play_pause=""
  9. else
  10. play_pause=""
  11. fi
  12. active=""
  13. urgent=""
  14. # Display if repeat mode is on / off
  15. tog_repeat=""
  16. if [[ $status == *"repeat: on"* ]]; then
  17. active="-a 4"
  18. elif [[ $status == *"repeat: off"* ]]; then
  19. urgent="-u 4"
  20. else
  21. tog_repeat=" Parsing error"
  22. fi
  23. # Display if random mode is on / off
  24. tog_random=""
  25. if [[ $status == *"random: on"* ]]; then
  26. [ -n "$active" ] && active+=",5" || active="-a 5"
  27. elif [[ $status == *"random: off"* ]]; then
  28. [ -n "$urgent" ] && urgent+=",5" || urgent="-u 5"
  29. else
  30. tog_random=" Parsing error"
  31. fi
  32. stop=""
  33. next=""
  34. previous=""
  35. music=""
  36. # Variable passed to rofi
  37. options="$previous\n$play_pause\n$stop\n$next\n$tog_repeat\n$tog_random"
  38. # Get the current playing song
  39. current=$(mpc current)
  40. # If mpd isn't running it will return an empty string, we don't want to display that
  41. if [[ -z "$current" ]]; then
  42. current="-"
  43. fi
  44. # Spawn the mpd menu with the "Play / Pause" entry selected by default
  45. chosen="$(echo -e "$options" | $rofi_command -p "$current" -dmenu $active $urgent -selected-row 1)"
  46. case $chosen in
  47. $previous)
  48. mpc -q prev && kunst --size 60x60 --silent
  49. ;;
  50. $play_pause)
  51. mpc -q toggle && kunst --size 60x60 --silent
  52. ;;
  53. $stop)
  54. mpc -q stop
  55. ;;
  56. $next)
  57. mpc -q next && kunst --size 60x60 --silent
  58. ;;
  59. $tog_repeat)
  60. mpc -q repeat
  61. ;;
  62. $tog_random)
  63. mpc -q random
  64. ;;
  65. esac