diff options
-rwxr-xr-x | bin/player | 37 | ||||
-rwxr-xr-x | bin/status-bar | 3 | ||||
-rwxr-xr-x | bin/wms | 24 | ||||
-rw-r--r-- | etc/xmobar/xmobarrc | 2 |
4 files changed, 35 insertions, 31 deletions
@@ -22,7 +22,7 @@ help() { - next: go to the next track - play-pause: play/pause - rotate: rotate across available MPRIS players - - current: show the current MPRIS player + - synopsis: show the current MPRIS player and title Manipulate the MPRIS audio player. @@ -32,7 +32,7 @@ help() { Change the current MPRIS player: - $ player current + $ player synopsis Play/pause: @@ -104,6 +104,29 @@ next_player() { fi } +format_player_name() { + sed 's|^firefox\.instance.*$|firefox|' +} + +formatted_player_title() { + TITLE="$( + playerctl --player="$CURRENT_PLAYER" metadata xesam:title \ + 2>/dev/null ||: + )" + if [ -z "$TITLE" ]; then + TITLE="$( + playerctl --player="$CURRENT_PLAYER" metadata xesam:url | + uri -d | + sed 's|^.*/home/andreh/Downloads/||' + )" + fi + if [ ${#TITLE} -gt 82 ]; then + printf '%s...\n' "$(printf '%s' "$TITLE" | head -c 80)" + else + printf '%s\n' "$TITLE" + fi +} + case "$ACTION" in backward) playerctl --player="$CURRENT_PLAYER" position 5- @@ -123,10 +146,14 @@ case "$ACTION" in rotate) PLAYER="$(next_player)" echo "$PLAYER" > "$CURRENT_PLAYER_PATH" - notify-send -t 1000 "$PLAYER" 'current MPRIS target' + notify-send -t 1000 -- \ + "$(printf '%s' "$PLAYER" | format_player_name)" \ + 'current MPRIS target' ;; - current) - printf '%s\n' "$CURRENT_PLAYER" + synopsis) + printf '%s: %s\n' \ + "$(echo "$CURRENT_PLAYER" | format_player_name)" \ + "$(formatted_player_title)" ;; *) printf 'Bad ACTION: "%s".\n\n' "$ACTION" >&2 diff --git a/bin/status-bar b/bin/status-bar index d560051..73632f6 100755 --- a/bin/status-bar +++ b/bin/status-bar @@ -11,6 +11,7 @@ use feature 'signatures'; no warnings ('experimental::signatures'); use Getopt::Std (); use JSON (); +use open IN => ':encoding(UTF-8)'; sub usage($fh) { print $fh <<~'EOF' @@ -85,7 +86,7 @@ while (my ($statusline) = (<STDIN> =~ /^,?(.*)/)) { # Prefix our own information (you coud also suffix or insert in the # middle). - my $mpris = `player current`; + my $mpris = `player synopsis`; chomp $mpris; my $vms = `vm status | awk '\$2=="up"' | wc -l`; @@ -19,7 +19,6 @@ help() { - uuid - date - clear-notification - - mpris Helper script to launch CLI commands, without having complex @@ -78,23 +77,6 @@ copy_and_notify() { "$STR" "$LABEL copied to clipboard" } -format_player_name() { - if echo "$1" | grep -Eq '^firefox\.instance.*'; then - echo 'firefox' - else - echo "$PLAYER" - fi -} - -format_player_title() { - TITLE="$(playerctl --player="$PLAYER" metadata xesam:title)" - if [ "${#TITLE}" -gt 82 ]; then - printf '%s...\n' "$(echo "$TITLE" | head -c 80)" - else - echo "$TITLE" - fi -} - case "$ACTION" in uuid) copy_and_notify "$(uuid)" 'UUID' @@ -105,12 +87,6 @@ case "$ACTION" in clear-notification) dunstctl close ;; - mpris) - PLAYER="$(player current)" - PLAYER_NAME="$(format_player_name "$PLAYER")" - PLAYER_TITLE="$(format_player_title "$PLAYER")" - printf '%s: %s\n' "$PLAYER_NAME" "$PLAYER_TITLE" - ;; *) printf 'Bad ACTION: %s.\n\n' "$ACTION" >&2 usage >&2 diff --git a/etc/xmobar/xmobarrc b/etc/xmobar/xmobarrc index 943c1ef..c851458 100644 --- a/etc/xmobar/xmobarrc +++ b/etc/xmobar/xmobarrc @@ -18,7 +18,7 @@ Config { "-h", "green", "-l", "red"] 10 - , Run CommandReader "forever x sleep 1 AND wms mpris 2>/dev/null" "mpris" + , Run CommandReader "forever x sleep 1 AND player synopsis 2>/dev/null" "mpris" ] , template = " %default:Master%| %mpris% } { %wlp0s20f3wi% | %cpu% | %battery% | %disku% | %memory% * %swap% | <fc=#5ea2a4>%date%</fc> " } |