dotfiles/bin/statusbar
2021-01-02 13:42:33 -08:00

60 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
#DATE=$(while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done)
DATE=$(date +'%Y-%m-%d %k:%M')
POWER=$(upower -i /org/freedesktop/UPower/devices/battery_BAT|grep percentage|awk '{print $2}')
BSTATE=$(upower -i /org/freedesktop/UPower/devices/battery_BAT|grep state|awk '{print $2}')
# fully-charged 🔌
# charging ⚡
# discharging 🔋
case "$BSTATE" in
fully-charged)
STATE="🔌"
;;
charging)
STATE="⚡"
;;
discharging)
STATE="🔋 "
;;
*)
STATE=""
;;
esac
# weather (https://github.com/chubin/wttr.in)
# add %l for location
WCACHE=~/.cache/thrrgilag/wttr
if [ ! -f $WCACHE ];
then
touch $WCACHE
fi
AGE=$(($(date +%s) - $(stat -c '%Y' "$WCACHE")))
if [ $AGE -gt 1800 ] || [ ! -s $WCACHE ];
then
curl -s en.wttr.in/?format="%l+%t+%C+%h+%w+%m" > $WCACHE
#echo "-" > $WCACHE
fi
WEATHER=$(cat $WCACHE)
# spotify
MCLASS=$(playerctl metadata --player=spotify --format '{{lc(status)}}')
MICON="🎵"
if [[ $MCLASS == "playing" ]]; then
MINFO=$(playerctl metadata --player=spotify --format '{{artist}} - {{title}}')
if [[ ${#MINFO} > 35 ]];
then
MINFO=$(echo $MINFO | cut -c1-35)"..."
fi
MTEXT=$MINFO" "$MICON" |"
elif [[ $class == "paused" ]];
then
MTEXT=$MICON" (paused) |"
elif [[ $class == "stopped" ]];
then
MTEXT=""
fi
echo "$MTEXT $WEATHER | $POWER $STATE | $DATE |"