aboutsummaryrefslogtreecommitdiff
path: root/scripts/scripts/cmusnp.sh
blob: b43c7e87674d04a4537f9e23933d4673a051d0d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# Display currently playing song from cmus
# Requires cmus

# colors
active="$( ~/scripts/get_xres color7 )"
inactive="$( ~/scripts/get_xres color7 )"

np_string=""

trunc() {
    max_length=$1
    text=$2
    length=${#text}
    (( length > max_length )) &&
        text=${text::$(( max_length ))}...
    echo "$text"
}

if pgrep -x "cmus" > /dev/null
then
	status=$( cmus-remote -Q | grep status\ | sed 's/status //' )
	artist=$( cmus-remote -Q | grep tag\ artist\ | sed 's/tag artist //' )
	title=$( cmus-remote -Q | grep tag\ title\ | sed 's/tag title //' )

	np_string="$title - $artist"
	np_string=$( trunc 35 "$np_string" )

	spc=$(( $(( 32 - ${#np_string} ))/2 ))
	spc="$( printf "%${spc}s" )"

	if [[ "$status" = *playing* ]]
	then
		echo -ne "%{F#FF0000}%{F#FFFFFF}PAUSE"
	elif [[ "$status" = *paused* ]]
	then
		echo -ne "PLAY"
	elif [[ "$status" = *stopped* ]]
	then
		echo -ne "START"
	fi

else
	echo 
fi