dotfiles/bin/statusbar
2021-10-11 10:23:16 -07:00

101 lines
2 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')
BATTERY=$(upower --enumerate|grep battery)
POWER="| $(upower -i $BATTERY|grep percentage|awk '{print $2}')"
BSTATE=$(upower -i $BATTERY|grep state|awk '{print $2}')
# fully-charged 🔌
# charging ⚡
# discharging 🔋
case "$BSTATE" in
fully-charged)
STATE="🔌 |"
;;
charging)
STATE="⚡ |"
;;
discharging)
STATE="🔋 |"
;;
*)
STATE=""
;;
esac
SSHD=$(systemctl list-unit-files|egrep ^sshd?.service|awk '{print $1}')
SSHDSTATUS=$(systemctl is-active $SSHD)
if [[ $SSHDSTATUS == "active" ]];
then
SSHWARN="🐧"
else
SSHWARN=""
fi
if [ -f /var/run/reboot-required ]
then
RBT="⚠️ "
else
RBT=""
fi
# swaymsg -t get_outputs
# LAPTOP="eDP-1"
# EXTERNAL="HDMI-A-1"
source $HOME/.config/sway/displays.sh
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="$(hostname -s)$E$L"
# weather (https://github.com/chubin/wttr.in)
# add %l for location
if [ -d ~/.cache/thrrgilag ];
then
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
fi
WEATHER=$(cat $WCACHE)
else
WEATHER=""
fi
# 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 $DISPSTAT $POWER $STATE $DATE | $SSHWARN$RBT"