diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-09-04 12:04:53 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-09-04 12:04:53 +0200 |
commit | 65b7f91e51d90e93c3d7c6704c0a8265467a8ea7 (patch) | |
tree | 88301071c7f1840b502f33cbd3b0f7c5e81b0c66 /Common/rofi/applets/menu/mpd.sh | |
parent | a77563ee1044ffa03f7c49e457a5f7c9f943188f (diff) | |
parent | e6df7072ab32493a561fc678eacc119b57981827 (diff) | |
download | dotfiles-65b7f91e51d90e93c3d7c6704c0a8265467a8ea7.tar.gz dotfiles-65b7f91e51d90e93c3d7c6704c0a8265467a8ea7.zip |
Merge branch 'master' of https://github.com/JakobS1n/dotfiles
Diffstat (limited to 'Common/rofi/applets/menu/mpd.sh')
-rwxr-xr-x | Common/rofi/applets/menu/mpd.sh | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Common/rofi/applets/menu/mpd.sh b/Common/rofi/applets/menu/mpd.sh new file mode 100755 index 0000000..3eb5498 --- /dev/null +++ b/Common/rofi/applets/menu/mpd.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +## Author : Aditya Shakya +## Mail : adi1090x@gmail.com +## Github : @adi1090x +## Twitter : @adi1090x + +style="$($HOME/.config/rofi/applets/menu/style.sh)" + +dir="$HOME/.config/rofi/applets/menu/configs/$style" +rofi_command="rofi -theme $dir/mpd.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 "%artist% - %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 |