dotfiles/bin/statusbar

90 lines
1.8 KiB
Text
Raw Normal View History

2021-01-02 21:42:33 +00:00
#!/bin/bash
#DATE=$(while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done)
DATE=$(date +'%Y-%m-%d %k:%M')
2021-04-07 21:55:55 +00:00
2021-04-07 19:50:24 +00:00
BATTERY=$(upower --enumerate|grep battery)
POWER="| $(upower -i $BATTERY|grep percentage|awk '{print $2}')"
BSTATE=$(upower -i $BATTERY|grep state|awk '{print $2}')
2021-01-02 21:42:33 +00:00
# fully-charged 🔌
# charging ⚡
# discharging 🔋
case "$BSTATE" in
fully-charged)
2021-02-20 00:57:06 +00:00
STATE="🔌 |"
2021-01-02 21:42:33 +00:00
;;
charging)
2021-02-20 00:57:06 +00:00
STATE="⚡ |"
2021-01-02 21:42:33 +00:00
;;
discharging)
2021-02-20 00:57:06 +00:00
STATE="🔋 |"
2021-01-02 21:42:33 +00:00
;;
*)
STATE=""
;;
esac
2021-04-07 21:55:55 +00:00
SSHDSTATUS=$(systemctl is-active ssh)
if [[ $SSHDSTATUS == "active" ]];
then
SSHWARN="⚠️ |"
else
SSHWARN=""
fi
source $HOME/.config/sway/displays.sh
# swaymsg -t get_outputs
# LAPTOP="eDP-1"
# EXTERNAL="HDMI-A-1"
LAPSTAT=$(swaymsg -t get_outputs -r|jq --arg DISP "$LAPTOP" '.[] | select(.name==$DISP) | .active')
if [[ $LAPSTAT == "true" ]];
then
L=" 💻"
else
L=""
fi
EXTSTAT=$(swaymsg -t get_outputs -r|jq --arg DISP "$EXTERNAL" '.[] | select(.name==$DISP) | .active')
if [[ $EXTSTAT == "true" ]];
then
E=" 🖥️"
else
E=""
fi
DISPSTAT="$E$L"
2021-01-02 21:42:33 +00:00
# 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
2021-04-07 21:55:55 +00:00
echo "$MTEXT $WEATHER $DISPSTAT $POWER $STATE $DATE | $SSHWARN"