Files
dotfiles/.config/polybar/scripts/media.sh
Julian Prein b96d32996b *: Wrap lines at 80 columns where appropriate
Wrap lines at 80 columns where appropriate and I had the energy to think
about how/where to wrap.

There are still lines longer than that, which I plan to wrap in the
future. But that is enough for now.
2022-06-23 23:59:00 +02:00

34 lines
878 B
Bash
Executable File

#!/bin/sh
command -v playerctl >/dev/null 2>&1 || { printf "playerctl not found.\n" >&2; exit 1; }
metadata="$(playerctl metadata --format '{{status}} {{artist}}' 2>/dev/null)"
title="$(playerctl metadata --format '{{title}}' 2>/dev/null)"
duration="$(2>/dev/null playerctl metadata \
--format '({{duration(position)}}|{{duration(mpris:length)}})'
)"
if [ -n "$metadata" ] && [ "$metadata" != "No players found" ]; then
# Extract status (Playing|Paused)
status="${metadata%% *}"
artists="${metadata#* }"
if [ "$status" = "Playing" ]; then
icon="" # \uf04b
else
icon="" # \uf04c
fi
if [ ${#artists} -gt 15 ]; then
artists="$(echo "$artists" | cut -c -15)..."
fi
art_len=${#artists}
if [ ${#title} -gt $((30 + 15 - art_len)) ]; then
title="$(echo "$title" | cut -c -30)..."
fi
printf "$icon $artists - $title $duration"
fi
printf "\n"