diff options
Diffstat (limited to 'ar/.local/bin/statusbar/sb-music')
| -rwxr-xr-x | ar/.local/bin/statusbar/sb-music | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/ar/.local/bin/statusbar/sb-music b/ar/.local/bin/statusbar/sb-music index b0a911a..1134d12 100755 --- a/ar/.local/bin/statusbar/sb-music +++ b/ar/.local/bin/statusbar/sb-music @@ -1,8 +1,8 @@ #!/bin/bash truncate_string() { - local input="$1" - local max_length="$2" + input="$1" + max_length="$2" if [ "${#input}" -gt "$max_length" ]; then echo "${input:0:$((max_length - 2))}.." else @@ -10,19 +10,24 @@ truncate_string() { fi } -filter() { +signal="$(awk -F', *' -v name="${0##*/}" '$2 ~ name {print $3+0}' "${XDG_SOURCES_HOME:-${HOME}/.local/src}/suckless/dwmblocks/config.def.h")" + +[ "$signal" -eq 0 ] && { + pidof -x sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 & +} + +status() { if ps -C mpd >/dev/null 2>&1; then screen_width=$(xrandr | awk '/\*/ {split($1, res, "x"); print res[1]; exit}') artist=$(mpc current -f %artist%) title=$(mpc current -f %title%) if [ "$screen_width" -le 2048 ]; then - max_length=$((screen_width / 100)) + length="$(grep 'MAX_BLOCK_OUTPUT_LENGTH' ~/.local/src/suckless/dwmblocks/config.def.h | awk '{print $3}')" + max_length="${length:+$((length / 3))}" + max_length="${max_length:-15}" artist=$(truncate_string "$artist" "$max_length") title=$(truncate_string "$title" "$max_length") - else - artist="$(mpc current -f %artist%)" - title="$(mpc current -f %title%)" fi case "$(mpc status %state%)" in @@ -36,8 +41,10 @@ filter() { [ "$(mpc status %random%)" = "on" ] && indicators="${indicators}🔂" [ "$(mpc status %repeat%)" = "on" ] && indicators="${indicators}🔁" - case "$(awk -F',' -v name="${0##*/}" '$0 ~ name {gsub(/[[:space:]]/, "", $3); print $3}' "${XDG_SOURCES_HOME:-${HOME}/.local/src}/suckless/dwmblocks/config.def.h")" in - 0) echo "$prefix$artist - $title${indicators:+$indicators}" ;; + case "$signal" in + 0) + echo "$prefix$artist - $title${indicators:+$indicators}" + ;; [1-9]*) current_time=$(mpc status %currenttime%) total_time=$(mpc status %totaltime%) @@ -45,22 +52,16 @@ filter() { ;; *) return ;; esac - fi } -[ "$(awk -F',' -v name="${0##*/}" '$0 ~ name {print $3; exit}' "${XDG_SOURCES_HOME:-${HOME}/.local/src}/suckless/dwmblocks/config.def.h")" -eq 0 ] && { - pidof -x sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 & -} +mpc status %state% | grep -q "stopped" || status -# Handling interaction based on button press case $BLOCK_BUTTON in -1) # left click, opens ncmpcpp - mpc status | filter - setsid -f "$TERMINAL" -e ncmpcpp - ;; -2) mpc toggle | filter ;; # middle click, pause/unpause -3) # right click +1) setsid -f "$TERMINAL" -e ncmpcpp ;; # left click, opens ncmpcpp +2) mpc toggle ;; # middle click, pause/unpause +3) # right click + { [ -n "$(mpc current)" ] && [ -n "$(mpc queued)" ]; } && notify-send "🎵 $(mpc current)" "⏭️ $(mpc queued)" notify-send "🎵 Music module" "\- Shows mpd song playing and status - 🎵 if playing - ⏸ if paused @@ -70,10 +71,8 @@ case $BLOCK_BUTTON in - Left click opens ncmpcpp - Middle click pauses/unpause - Scroll changes track" - { [ -n "$(mpc current)" ] && [ -n "$(mpc queued)" ]; } && notify-send "🎵 $(mpc current)" "⏭️ $(mpc queued)" ;; -4) mpc prev | filter ;; # scroll up, previous -5) mpc next | filter ;; # scroll down, next +4) mpc prev ;; # scroll up, previous +5) mpc next ;; # scroll down, next 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; -*) mpc status | filter ;; # default, show current status esac |
