dotfiles

Configuration for the software I use.
git clone https://git.sr.ht/~jbauer/dotfiles
Log | Files | Refs | README | LICENSE

commit 8ff6e339ffc27248a1833d02ef7beacec6c85517
parent 43959775c195977a7beba3e0704939ebd1abcb78
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Thu, 17 Dec 2020 02:15:03 -0500

Add now-playing script

Diffstat:
A.local/bin/now-playing.sh | 41+++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+), 0 deletions(-)

diff --git a/.local/bin/now-playing.sh b/.local/bin/now-playing.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +nowPlaying=$(cmus-remote -Q) +title=$(echo "$nowPlaying" | grep 'tag title' | cut -d' ' -f3-) +artist=$(echo "$nowPlaying" | grep 'tag artist' | cut -d' ' -f3-) +repeat=$(echo "$nowPlaying" | grep 'set repeat ' | cut -d' ' -f3-) +shuffle=$(echo "$nowPlaying" | grep 'set shuffle' | cut -d' ' -f3-) +duration=$(echo "$nowPlaying" | grep 'duration' | cut -d' ' -f2-) +position=$(echo "$nowPlaying" | grep 'position' | cut -d' ' -f2-) +curStatus=$(echo "$nowPlaying" | head -1 | cut -d' ' -f2) + +if [ "$curStatus" != "playing" ] && [ "$curStatus" != "paused" ]; then + printf "Nothing Playing" + exit 0 +fi + +# Truncate long title (e.g. "Burned Down Cigarettes" -> "Burned Down C...") +if [ "$(echo "$title" | wc -m)" -gt 16 ]; then + title=$( printf "%.16s" "$title" | sed 's/...$/.../') +fi + +# Truncate long artist name (e.g. "Midnight Ambassador" -> "Midnight Am.") +if [ "$(echo "$artist" | wc -m)" -gt 12 ]; then + artist=$( printf "%.12s" "$artist" | sed 's/.$/./') +fi + +((durationMinutes=$duration/60)) +((durationSeconds=$duration%60)) +((positionMinutes=$position/60)) +((positionSeconds=$position%60)) + +if [ "$shuffle" = "true" ]; then + icons=" " +fi +if [ "$repeat" = "true" ]; then + icons="$icons " +fi + +printf "\"%s\" by %s — %02d:%02d/%02d:%02d%s" "$title" "$artist" \ + "$positionMinutes" "$positionSeconds" "$durationMinutes" \ + "$durationSeconds" "$icons"