#!/bin/bash
source ~/.profile

# Setup statusbar and mail
speaker_muted=🔇
speaker_low=🔈
speaker_medium=🔉
speaker_high=🔊
brightness_symbol=🔅

# Check number of unread emails
messages() {
	printf "$(find ~/Mail -path '*INBOX*' -not -name \
	'.uidvalidity' -type f | grep -vE ',[^,]*S[^,]*$'| wc -l)"
}

volume() {
	v="$(pactl list sinks | grep '^[[:space:]]Volume:' | head -n 1 | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')"

	if [ $v -eq 0 ]; then
		i="īą"
	elif [ $v -le 50 ]; then
		i=""
	else
		i="īŠŊ"
	fi

	printf "$i $v"
}

DELAY=5m

while true; do
	mbsync -a
	sleep $DELAY
done &

while true; do
	xsetroot -name "ī›Ž Messages $(messages)  \
$(volume)  \
 $(date +"%c")"
   sleep $DELAY
done &

setxkbmap -option ctrl:swapcaps -option tilde:swapescape
picom -bfc
~/.fehbg
xbindkeys -f $HOME/Source/configs/xbindkeysrc

( mru update; mru updatedirs ) &

# Relaunch DWM if the binary changes, otherwise bail
csum=$(sha1sum $(which dwm))
new_csum=""
while true
do
	if [ "$csum" != "$new_csum"  ]
	then
		csum=$new_csum
		awesome
	else
		exit 0
	fi
	new_csum=$(sha1sum $(which dwm))
	sleep 0.5
done