d0tfiles

*nix dotfiles for arch linux setup
Log | Files | Refs | README | LICENSE

mpd (1745B)


      1 #!/bin/bash
      2 
      3 DIR="$HOME/.config/bspwm"
      4 
      5 rofi_command="rofi -theme $DIR/rofi/themes/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=""
     12 else
     13     play_pause=""
     14 fi
     15 active=""
     16 urgent=""
     17 
     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 
     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 music=""
     41 
     42 # Variable passed to rofi
     43 options="$previous\n$play_pause\n$stop\n$next\n$tog_repeat\n$tog_random"
     44 
     45 # Get the current playing song
     46 current=$(mpc current)
     47 # If mpd isn't running it will return an empty string, we don't want to display that
     48 if [[ -z "$current" ]]; then
     49     current="-"
     50 fi
     51 
     52 # Spawn the mpd menu with the "Play / Pause" entry selected by default
     53 chosen="$(echo -e "$options" | $rofi_command -p "$current" -dmenu $active $urgent -selected-row 1)"
     54 case $chosen in
     55     $previous)
     56         mpc -q prev && kunst --size 60x60 --silent
     57         ;;
     58     $play_pause)
     59         mpc -q toggle && kunst --size 60x60 --silent
     60         ;;
     61     $stop)
     62         mpc -q stop
     63         ;;
     64     $next)
     65         mpc -q next && kunst --size 60x60 --silent
     66         ;;
     67     $tog_repeat)
     68         mpc -q repeat
     69         ;;
     70     $tog_random)
     71         mpc -q random
     72         ;;
     73 esac