dotfiles/bin/statusbar
2021-06-01 05:47:25 -07:00

100 lines
1.9 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
SSHDSTATUS=$(systemctl is-active ssh)
if [[ $SSHDSTATUS == "active" ]];
then
SSHWARN="🐧|"
else
SSHWARN=""
fi
if [ -f /var/run/reboot-required ]
then
RBT="⚠️ "
else
RBT=""
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"
# 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"