dotfiles/bin/statusbar

105 lines
2 KiB
Text
Raw Permalink Normal View History

2021-01-02 21:42:33 +00:00
#!/bin/bash
2022-01-03 18:48:25 +00:00
# swaymsg -t get_outputs
# LAPTOP="eDP-1"
# EXTERNAL="HDMI-A-1"
LAPTOP="LVDS-1"
EXTERNAL="DP-1"
2021-01-02 21:42:33 +00:00
#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-10-11 17:23:16 +00:00
SSHD=$(systemctl list-unit-files|egrep ^sshd?.service|awk '{print $1}')
SSHDSTATUS=$(systemctl is-active $SSHD)
2021-04-07 21:55:55 +00:00
if [[ $SSHDSTATUS == "active" ]];
then
2021-07-17 17:35:16 +00:00
SSHWARN="🐧"
2021-04-07 21:55:55 +00:00
else
SSHWARN=""
fi
2021-06-01 12:47:25 +00:00
if [ -f /var/run/reboot-required ]
then
RBT="⚠️ "
else
RBT=""
fi
2021-04-07 21:55:55 +00:00
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
2021-08-10 13:27:53 +00:00
DISPSTAT="$(hostname -s)$E$L"
2021-04-07 21:55:55 +00:00
2021-01-02 21:42:33 +00:00
# weather (https://github.com/chubin/wttr.in)
# add %l for location
2021-05-11 04:51:09 +00:00
if [ -d ~/.cache/thrrgilag ];
2021-01-02 21:42:33 +00:00
then
2021-05-11 04:51:09 +00:00
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=""
2021-01-02 21:42:33 +00:00
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
2021-06-01 12:47:25 +00:00
echo "$MTEXT $WEATHER $DISPSTAT $POWER $STATE $DATE | $SSHWARN$RBT"