#!/bin/sh filter() { artist_track="" status_icon="" modes="" track_info_captured=false # Read input line by line while IFS= read -r line; do # Capture the first line with artist and track name if [ "$track_info_captured" = false ]; then # Check if the line contains typical status info (e.g., "volume:") instead of artist-track if echo "$line" | grep -q "volume:"; then # No song is playing, exit with empty output echo "" return fi artist_track="$line" track_info_captured=true continue fi # Check for track status (paused or playing) if echo "$line" | grep -q "\[paused\]"; then status_icon=" " elif echo "$line" | grep -q "\[playing\]"; then status_icon="" fi # Check for modes: consume, random, repeat, single if echo "$line" | grep -q "consume: on"; then modes="${modes} " fi if echo "$line" | grep -q "random: on"; then modes="${modes} " fi if echo "$line" | grep -q "repeat: on"; then modes="${modes} " fi if echo "$line" | grep -q "single: on"; then modes="${modes}1 " fi done # After all lines processed, output the result only if artist_track is valid if [ "$track_info_captured" = true ] && [ -n "$artist_track" ]; then # Trim trailing space from modes if any modes=$(echo "$modes" | sed 's/[[:space:]]*$//') # Only add "|" if there are modes if [ -n "$modes" ]; then echo "$status_icon$artist_track | $modes" else echo "$status_icon$artist_track" fi else echo "" fi } pidof -x sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 & case $BLOCK_BUTTON in 1) mpc status | filter ; setsid -f "$TERMINAL" -e rmpc >/dev/null 2>&1 < /dev/null;; # right click, pause/unpause 2) mpc toggle | filter ;; # right click, pause/unpause 3) mpc status | filter ; notify-send " Music module" "\- Shows mpd song playing. -  paused. -  consume mode. -  shuffle mode. -  repeat mode. - 1 single mode. - Left click opens rmpc. - Middle click pauses. - Scroll changes track.";; # right click, pause/unpause 4) mpc prev | filter ;; # scroll up, previous 5) mpc next | filter ;; # scroll down, next 8) mpc status | filter ; setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 < /dev/null ;; *) mpc status | filter ;; esac