mpd.sh 2.0 KB

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