39 lines
1.2 KiB
Bash
Executable File
39 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Separate truncation limits for song title vs artist name (song gets more space).
|
|
truncs=13
|
|
trunca=10
|
|
# playerctl queries the active MPRIS2 media player (Spotify, VLC, browser, etc.)
|
|
# and returns the metadata field using its go-template format.
|
|
song=$(playerctl metadata --format '{{ title }}')
|
|
artist=$(playerctl metadata --format '{{ artist }}')
|
|
#echo ${sample}
|
|
|
|
# Truncate song title to truncs chars and append "…" if it exceeds the limit.
|
|
if [ ${#song} -gt $truncs ]; then
|
|
songt=$(echo $song | head -c $truncs | sed 's/$/…/')
|
|
else
|
|
if [ ${#song} -ne 0 ]; then
|
|
songt=$(echo ${song})
|
|
else
|
|
# No media playing — use "None" so the Eww widget always has content.
|
|
songt=$(echo None)
|
|
fi
|
|
fi
|
|
|
|
# Same truncation logic for the artist field with a shorter limit.
|
|
if [ ${#artist} -gt $trunca ]; then
|
|
artistt=$(echo $artist | head -c $trunca | sed 's/$/…/')
|
|
else
|
|
if [ ${#artist} -ne 0 ]; then
|
|
artistt=$(echo ${artist})
|
|
else
|
|
artistt=$(echo None)
|
|
fi
|
|
fi
|
|
# Output as "song|artist" — the Eww widget splits on "|" to show them separately.
|
|
echo "${songt}|${artistt}"
|
|
|
|
|
|
#hyprctl activewindow | grep title: | awk -F: '{print $2}' | head -c $trunc | sed 's/$/.../'
|
|
|