mpd (1760B)
1 #!/bin/bash 2 3 STYLE="default" 4 5 rofi_command="rofi -theme $STYLE/mpd.rasi" 6 7 # Gets the current status of mpd (for us to parse it later on) 8 status="$(mpc status)" 9 # Defines the Play / Pause option content 10 if [[ $status == *"[playing]"* ]]; then 11 play_pause=" Pause" 12 else 13 play_pause=" Play" 14 fi 15 active="" 16 urgent="" 17 18 # Display if repeat mode is on / off 19 tog_repeat=" 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=" Error" 26 fi 27 28 # Display if random mode is on / off 29 tog_random=" Shuffle" 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=" Error" 36 fi 37 38 stop=" Stop" 39 next=" Next" 40 previous=" Previous" 41 music="" 42 43 # Variable passed to rofi 44 options="$play_pause\n$stop\n$previous\n$next\n$tog_repeat\n$tog_random" 45 46 # Get the current playing song 47 current=$(mpc -f %title% current) 48 # If mpd isn't running it will return an empty string, we don't want to display that 49 if [[ -z "$current" ]]; then 50 current="-" 51 fi 52 53 # Spawn the mpd menu with the "Play / Pause" entry selected by default 54 chosen="$(echo -e "$options" | $rofi_command -p "$current" -dmenu $active $urgent -selected-row 0)" 55 case $chosen in 56 $previous) 57 mpc -q prev && kunst --size 60x60 --silent 58 ;; 59 $play_pause) 60 mpc -q toggle && kunst --size 60x60 --silent 61 ;; 62 $stop) 63 mpc -q stop 64 ;; 65 $next) 66 mpc -q next && kunst --size 60x60 --silent 67 ;; 68 $tog_repeat) 69 mpc -q repeat 70 ;; 71 $tog_random) 72 mpc -q random 73 ;; 74 esac