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
46
47
48
49
50
51
52
53
#!/bin/sh
while true; do
cpuUtil=$(vmstat -c2| awk 'NR>2 {print 100-$(NF);}' | tail -1)
cpuTemp=$(sysctl hw.sensors.ksmn0.temp0 | cut -d= -f2 | cut -d. -f1)
memUtil=$(top -1b | head -4 | tail -1 | cut -d' ' -f3 | cut -d'/' -f1)
diskUtil=$(df -P | grep /home | awk '{print $5}')
localTime=$(date +"%Y-%m-%d %H:%M")
europeTime=$(TZ=Europe/Berlin date +"%H:%M")
# Begin NowPlaying Section
nowPlaying=$(cmus-remote -Q 2>/dev/null)
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
nowPlaying="Nothing Playing"
else
# 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))
icons=""
if [ "$shuffle" = "true" ]; then
icons="$icons "
fi
if [ "$repeat" = "true" ]; then
icons="$icons "
fi
nowPlaying=$(printf "\"%s\" by %s — %02d:%02d/%02d:%02d%s" \
"$title" "$artist" "$positionMinutes" "$positionSeconds" \
"$durationMinutes" "$durationSeconds" "$icons")
fi
# End NowPlaying Section
xsetroot -name "$nowPlaying;$cpuTemp°C $cpuUtil% $memUtil $diskUtil $localTime/$europeTime"
done