From a00305038323e8668e87e4f2ebd59fcfaff1d6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Dudr?= Date: Tue, 27 Dec 2022 11:23:53 +0100 Subject: [PATCH] scripts: mprisctl - wrap playerctl in more sensible way --- bin/executable_mprisctl | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 bin/executable_mprisctl diff --git a/bin/executable_mprisctl b/bin/executable_mprisctl new file mode 100644 index 0000000..28b5ec0 --- /dev/null +++ b/bin/executable_mprisctl @@ -0,0 +1,49 @@ +#!/bin/zsh +set -e + +typeset -a playing +typeset -a paused +typeset -a all + +process() { + local state=$1 + shift + local pl + + if (( ${#${(P)state}} > 1)) + then + pl=$(rofi -dmenu<<<${(FP)state}) + else + pl=${(FP)state} + fi + [[ -n $pl ]] && playerctl -p $pl $@ +} + +while read player ps +do + all+=$player + case $ps in + Playing) playing+=$player ;; + Paused) paused+=$player ;; + esac +done < <(playerctl -a status --format '{{playerName}} {{status}}') + +case $1 in + toggle) + if (( ${#playing} )) + then + xargs -n1 playerctl pause -p <<<${playing} + else + process paused play + fi + ;; + next) + process playing next + ;; + prev) + process playing previous + ;; + open) + shift + process all open "$@" +esac