summaryrefslogblamecommitdiffstats
path: root/dwm_bar
blob: 487c9a32bc40db5881a53d6f41af899b8d850fbd (plain) (tree)

































































                                                                                                                
#!/bin/env sh

# INIT
printf "$$" > ~/.cache/pidofbar
sec=0

update_memory () { 
	memory="$(free -h | sed -n "2s/\([^ ]* *\)\{2\}\([^ ]*\).*/\2/p")"
}

update_time () { 
	time="$(date "+[  %a %d %b ] [  %I:%M %P ]")" 
}

update_bat () { 
	# you might need to change the path depending on your device
	read -r bat_status </sys/class/power_supply/BAT0/status
	read -r bat_capacity </sys/class/power_supply/BAT0/capacity
	if [ "$bat_status" = "Charging" ]; then
		bat_status=""
	elif [ "$bat_capacity" -gt 80 ]; then
		bat_status=""
	elif [ "$bat_capacity" -gt 60 ]; then
		bat_status=""
	elif [ "$bat_capacity" -gt 40 ]; then
		bat_status=""
	elif [ "$bat_capacity" -gt 20 ]; then
		bat_status=""
	else 
		bat_status=""
	fi
	bat="$bat_status $bat_capacity%"
}

update_vol () { 
	vol="$([ "$(pamixer --get-mute)" = "false" ] && printf ' ' || printf ' ')$(pamixer --get-volume)%"
}

# We have to run this only once.
update_vol

display () { 
	xsetroot -name "[  $memory ] [ $vol ] $time"
}

# Handling receiving signal
# RTMIN = 34 (always)
trap	"update_vol;display"	"RTMIN"

## kill -m "$(cat ~/.cache/pidofbar)"
# where m = 34 + n

while true
do
	sleep 1 &
  wait && { 
		# to update item ever n seconds with a offset of m
		## [ $((sec % n)) -eq m ] && udpate_item
		[ $((sec % 5 )) -eq 0 ] && update_time
		[ $((sec % 15)) -eq 0 ] && update_memory

		# how often the display updates ( 5 seconds )
		[ $((sec % 5 )) -eq 0 ] && display
		sec=$((sec + 1))
	}
done