aboutsummaryrefslogtreecommitdiff
path: root/linux/rofi/applets/android/mpd.sh
diff options
context:
space:
mode:
authorjakob.stendahl <jakob.stendahl@infomedia.dk>2024-01-23 11:13:18 +0100
committerjakob.stendahl <jakob.stendahl@infomedia.dk>2024-01-23 11:13:18 +0100
commit72efe134f645a5212f875c153dd8db4a64cbe968 (patch)
treed23229285071bf381515657b94919852ebf426c9 /linux/rofi/applets/android/mpd.sh
parente33d5f8d10d34e5a3a4bb292015961dd574f4c93 (diff)
downloaddotfiles-72efe134f645a5212f875c153dd8db4a64cbe968.tar.gz
dotfiles-72efe134f645a5212f875c153dd8db4a64cbe968.zip
changes
Diffstat (limited to 'linux/rofi/applets/android/mpd.sh')
-rwxr-xr-xlinux/rofi/applets/android/mpd.sh76
1 files changed, 76 insertions, 0 deletions
diff --git a/linux/rofi/applets/android/mpd.sh b/linux/rofi/applets/android/mpd.sh
new file mode 100755
index 0000000..6f15be0
--- /dev/null
+++ b/linux/rofi/applets/android/mpd.sh
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+
+## Author : Aditya Shakya
+## Mail : adi1090x@gmail.com
+## Github : @adi1090x
+## Twitter : @adi1090x
+
+dir="$HOME/.config/rofi/applets/android"
+rofi_command="rofi -theme $dir/six.rasi"
+
+# Gets the current status of mpd (for us to parse it later on)
+status="$(mpc status)"
+# Defines the Play / Pause option content
+if [[ $status == *"[playing]"* ]]; then
+ play_pause=""
+else
+ play_pause=""
+fi
+active=""
+urgent=""
+
+# Display if repeat mode is on / off
+tog_repeat=""
+if [[ $status == *"repeat: on"* ]]; then
+ active="-a 4"
+elif [[ $status == *"repeat: off"* ]]; then
+ urgent="-u 4"
+else
+ tog_repeat=" Parsing error"
+fi
+
+# Display if random mode is on / off
+tog_random=""
+if [[ $status == *"random: on"* ]]; then
+ [ -n "$active" ] && active+=",5" || active="-a 5"
+elif [[ $status == *"random: off"* ]]; then
+ [ -n "$urgent" ] && urgent+=",5" || urgent="-u 5"
+else
+ tog_random=" Parsing error"
+fi
+stop=""
+next=""
+previous=""
+
+# Variable passed to rofi
+options="$previous\n$play_pause\n$stop\n$next\n$tog_repeat\n$tog_random"
+
+# Get the current playing song
+current=$(mpc -f %title% current)
+# If mpd isn't running it will return an empty string, we don't want to display that
+if [[ -z "$current" ]]; then
+ current="-"
+fi
+
+# Spawn the mpd menu with the "Play / Pause" entry selected by default
+chosen="$(echo -e "$options" | $rofi_command -p " $current" -dmenu $active $urgent -selected-row 1)"
+case $chosen in
+ $previous)
+ mpc -q prev && notify-send -u low -t 1800 " $(mpc current)"
+ ;;
+ $play_pause)
+ mpc -q toggle && notify-send -u low -t 1800 " $(mpc current)"
+ ;;
+ $stop)
+ mpc -q stop
+ ;;
+ $next)
+ mpc -q next && notify-send -u low -t 1800 " $(mpc current)"
+ ;;
+ $tog_repeat)
+ mpc -q repeat
+ ;;
+ $tog_random)
+ mpc -q random
+ ;;
+esac