Created
May 25, 2020 14:15
-
-
Save jechasteen/63fe80f70d85fb09b7ca2eb444072ac4 to your computer and use it in GitHub Desktop.
A simple status bar for dwm written in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
# Refresh timer, seconds | |
REFRESH=5 | |
# Weather - wttr.in/help | |
LOCALITY=45403 | |
FORMAT=3 | |
# unicode symbols/icons | |
SEP=⎥ | |
ICO_ETH=🖧 | |
battery_state() | |
{ | |
CHARGING="$(acpi | awk '{printf "%s: %s", $4, $3}')" | |
STATE="$(echo $CHARGING | sed 's/,//g')" | |
if [[ "$STATE" == *"Unknown"* ]]; then | |
STATE="Charged" | |
fi | |
echo "$STATE" | |
} | |
wttr() | |
{ | |
local request="wttr.in/${LOCALITY}?format=${LOCALITY}" | |
[ "$(tput cols)" -lt 125 ] && request+='?n' | |
echo $(curl -sH "Accept-Language: ${LANG%_*}" --compressed "$request") | |
} | |
check_internet() | |
{ | |
wget -q --spider http://google.com | |
if [ $? -eq 0 ]; then | |
echo 1 | |
else | |
echo 0 | |
fi | |
} | |
x=0 | |
while true; do | |
WTTR=$WTTR | |
if (( x > 450 )) || (( x == 0 )); then | |
WTTR=$(wttr) | |
fi | |
DATE="$(date +'%a %d %b %Y %R')" | |
ETH="$ICO_ETH: $(nmcli d | grep ethernet | awk '{print $4}')" | |
WIFI="wifi: $(nmcli d | grep wifi | awk '{print $4}')" | |
BAT=$(battery_state) | |
declare -a ORDER=("$WTTR" "$BAT" "$ETH" "$WIFI" "$DATE") | |
STATS="$SEP" | |
for i in "${ORDER[@]}"; do | |
STATS="$STATS $i $SEP" | |
done | |
xsetroot -name "$STATS" | |
check_internet | |
if [$? -eq 1 ]; then | |
x=$((x+1)) | |
fi | |
sleep $REFRESH | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment