total re-write and cleanup. removed all the old stuff and only do one xsetroot output to avoid flashing.
This commit is contained in:
@@ -4,74 +4,32 @@ pgrep -x "$(basename "$0")" | grep -v $$ >/dev/null && exit 0
|
||||
|
||||
xsetroot -name "Loading ..."
|
||||
|
||||
while (true); do
|
||||
while true; do
|
||||
final_output=""
|
||||
|
||||
#set date: 04.03 15:22
|
||||
timedate=$(date +"%m.%d %H:%M")
|
||||
|
||||
## memory in use
|
||||
#mem=$(free -m | grep Mem | awk '{print $7}')
|
||||
|
||||
## load average
|
||||
#loadavg=$(cat /proc/loadavg | awk '{print $1 " " $2 " " $3}')
|
||||
|
||||
|
||||
check_mpd() {
|
||||
# check if mpd is playing
|
||||
# if yes, output volume and song
|
||||
check_play=$(mpc status | grep "playing")
|
||||
if [ ! -z "$check_play" ]; then
|
||||
play="[ $(mpc status | head -n 1) ]"
|
||||
## volume from mopidy, not useful, use master volume below
|
||||
#vol="[$(mpc vol | cut -c 8-)]"
|
||||
else
|
||||
#otherwise hide it
|
||||
vol=""
|
||||
play=""
|
||||
fi
|
||||
}
|
||||
|
||||
# function to call to update volume
|
||||
# this is so I don't have to constantly poll it every 0.5
|
||||
set_volume() {
|
||||
## using pactl was really unreliable
|
||||
#sound_card="$(pactl list sinks short | grep -i audioengine | awk '{print $1}')"
|
||||
#sound_card=3
|
||||
#vol="$(pactl list sinks | grep '^[[:space:]]Volume:' | head -n $sound_card | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,')%"
|
||||
vol="$(pulsemixer --get-volume | awk '{print $1}')%"
|
||||
}
|
||||
|
||||
### mouse charging
|
||||
# get state (eg "charging")
|
||||
#mouse_state="$(upower -i /org/freedesktop/UPower/devices/battery_hidpp_battery_6 | grep state | awk '{print $2}')"
|
||||
battery_name=$(upower --dump | grep Device.*battery | awk '{print $2}')
|
||||
mouse_state="$(upower -i $battery_name | grep state | awk '{print $2}')"
|
||||
final_output=$(date +"%m.%d %H:%M")
|
||||
|
||||
# get charge percentage
|
||||
#mouse_charge="$(upower -i $battery_name | grep percentage | awk '{print $2}')"
|
||||
mouse_charge=$(< /sys/class/power_supply/BAT0/capacity)
|
||||
# if the mouse is charging, set state to percentage. otherwise dont show it ("")
|
||||
if [ $mouse_state == "charging" ] && [ $mouse_state != "discharging" ]; then
|
||||
mouse_status="$mouse_charge%+"
|
||||
else
|
||||
mouse_status="$mouse_charge%"
|
||||
fi
|
||||
if [[ -d "/sys/class/power_supply/BAT0" ]]; then
|
||||
battery_output="$(< /sys/class/power_supply/BAT0/capacity)%"
|
||||
|
||||
# volume up/down scripts will SIGHUP this PID
|
||||
# when you receive SIGHUP just run set_volume()
|
||||
trap set_volume SIGHUP
|
||||
# add the + sign if its charging
|
||||
battery_status=$(< /sys/class/power_supply/BAT0/status)
|
||||
if [[ "$battery_status" == "Charging" ]]; then
|
||||
battery_output="${battery_output}+"
|
||||
fi
|
||||
final_output="${battery_output} ${final_output}"
|
||||
fi
|
||||
|
||||
### weather stuff
|
||||
wttr_file="/tmp/weather"
|
||||
if [[ -s "$wttr_file" ]]; then
|
||||
wttr=$(<"$wttr_file")
|
||||
xsetroot -name "$mouse_status $play $vol $wttr $timedate"
|
||||
else
|
||||
# output to status bar
|
||||
xsetroot -name "$mouse_status $play $vol $timedate"
|
||||
final_output="${wttr} ${final_output}"
|
||||
fi
|
||||
|
||||
# final output to status bar
|
||||
#xsetroot -name "$mouse_status $play $vol $timedate"
|
||||
xsetroot -name "$mouse_status $timedate"
|
||||
sleep 0.5;
|
||||
xsetroot -name "$final_output"
|
||||
sleep 1;
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user