mpd.sh 1.9 KB

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