Centurion / Scripts / dwm-status

#!/bin/bash
# Status script for dwm
# colours: 01:normal 02:white 03:red 04:green 05:yellow 
# 06:blue 07:cyan 08:magenta 09:grey

music(){
    track="$(mpc current)"
    artist="${track%%- *}"
    title="${track##*- }"
    if [[ -n "$artist" ]]; then
        echo -e "\x08$artist\x01\x06$title\x01 •"
    fi
}

mbt(){
    tmp="$(awk '/^MB/ {print +$3}' <(sensors))"
    if [[ "$tmp" -lt "55" ]]; then
        echo -e "MB \x07$tmp\x01"
    else
        echo -e "\x03MB $tmp\x01"
    fi
}

gpu(){
    tmp="$(nvidia-settings -q gpucoretemp -t)"
    echo -e "GPU \x06$tmp\x01"
}

mem(){
	mem="$(awk '/^-/ {print $3}' <(free -m))"
	echo -e "\x04$mem\x01"
}

   # CPU line courtesy Procyon:i
   # https://bbs.archlinux.org/viewtopic.php?pid=874333#p874333
cpu(){
	read cpu a b c previdle rest < /proc/stat
	prevtotal=$((a+b+c+previdle))
	sleep 0.5
	read cpu a b c idle rest < /proc/stat
	total=$((a+b+c+idle))
	cpu="$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))"
	echo -e "\x05$cpu%\x01"
	}

hdd(){
    hd="$(awk '
    {i=$5} /boot/ {a=i}; /root/ {b=i}; /home/ {c=i}; /media/ {d=i} 
    END {if (/media/) print a,b,c,d; else print a,b,c}
    ' <(df -P))"
	echo -e "\x08$hd\x01"
}

eml(){
	maildirs="$HOME/Mail/*/INBOX/new/"
	ml="$(find $maildirs -type f | wc -l)"
	if [[ $ml -eq 0 ]]; then
		echo "0"
	else
		echo -en "\x03$ml\x01"
	fi
}

pac(){
	pup="$(pacman -Qqu --dbpath /tmp/checkup-db-jason/ | wc -l)"
	if [[ $pup -eq 0 ]]; then
	    echo "0"
	else
	    echo -en "\x05$pup\x01"
	fi
}

ups(){
    ups="$(awk '$0 !~ /tamsyn/' /tmp/aurupdates* | wc -l)"
    if [[ $ups -eq 0 ]]; then
        echo "0"
    else echo -en "\x05$ups\x01"
    fi
}

aur(){
    aur="$(awk '$0 !~ /^No /' /tmp/aurphans* | wc -l)"
    if [[ $aur -gt 0 ]]; then
        echo -en "\x03*\x01"
    fi
}

int(){
    int="$("$HOME/Scripts/speed")"
    echo -e "$int"
}

dte(){
	dte="$(date "+%I:%M")"
	echo -e "\x02$dte\x01"
}

# Pipe to status bar
xsetroot -name "$(music) $(mbt) $(gpu) • CPU $(cpu) MEM $(mem) • HDD $(hdd) \
• EML $(eml) PKG $(pac) AUR $(ups)$(aur) • ETH $(int) • $(dte) "
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.