about summary refs log blame commit diff
path: root/scripts/dwm-status
blob: 25690534001da56373219ccbd94f8943c249d6fe (plain) (tree)
1
2
         
 


















                                                                              








                                                                                                                                                                                          


                     
                                 
                                                                                       




































                                                                                
                
    
#!/bin/sh

# This script sets the statusbar with the xsetroot command at the end. Have it
# started by ~/.xinitrc or ~/.xprofile.

# Set the deliminter character.

delim="|"


# Here is the (big) function that outputs the appearance of the statusbar. It
# can really be broken down into many submodules which I've commented and
# explained.
status() { \

	echo $(python /home/baitinq/.config/polybar/scripts/weather.py)

	echo "$delim"

	# Get the volume of ALSA's master volume output.  Show an icon if or
	# not muted.
	active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}')
	curStatus=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | awk '/muted/{ print $2}')
	volume=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | grep 'volume:' | grep -E -v 'base volume:' | awk -F : '{print $3}' | grep -o -P '.{0,3}%'| sed s/.$// | tr -d ' ')
	if [ "${curStatus}" = 'yes' ]
	then
			echo " $volume%"
	else
			echo " $volume%"
	fi

	echo "$delim"

	# Wifi quality percentage
	grep "^\s*w" /proc/net/wireless | awk '{ print "", int($3 * 100 / 70) "%" }'

	# Show unread mail
	command -v mw >/dev/null 2>&1 &&
		echo "$delim" &&
		du -a ~/Mail/*/INBOX/new/* 2>/dev/null | wc -l | sed 's/^/:/'
		echo "$delim"

	# Will show all batteries with approximate icon for remaining power.
	for x in /sys/class/power_supply/BAT?/capacity;
	do
	case "$(cat $x)" in
		100|9[0-9])	echo "" ;;
		8[0-9]|7[0-9])	echo "" ;;
		6[0-9]|5[0-9])	echo "" ;;
		4[0-9]|3[0-9])	echo "" ;;
		*)		echo "" ;;
	esac
	done && echo "$delim"

	# Date and time.
	date '+%Y %b %d (%a) %I:%M%p'
	}

while :; do
	# So all that big status function was just a command that quicking gets
	# what we want to be the statusbar. This xsetroot command is what sets
	# it. Note that the tr command replaces newlines with spaces. This is
	# to prevent some weird issues that cause significant slowing of
	# everything in dwm. Note entirely sure of the cause, but again, the tr
	# command easily avoids it.
	xsetroot -name "$(status | tr '\n' ' ')"

	# Check to see if new weather report is needed.

	# Sleep for a minute after changing the status bar before updating it
	# again. Note that the `refbar` "refreshes" the statusbar by killing
	# this command. Feel free to change the time interval if you want.
	sleep 1s
done