summaryrefslogtreecommitdiff
path: root/bin/statusbar
diff options
context:
space:
mode:
authorSam Nystrom <sam@samnystrom.dev>2023-04-16 18:02:47 -0500
committerSam Nystrom <sam@samnystrom.dev>2023-04-16 18:02:47 -0500
commitcf0972fe4b73a55f9e8c19d5565fa21470862cd9 (patch)
tree75878076f0d32c684e6f401ba8e4fecff3cf381b /bin/statusbar
parentd15e03aa71f055d2354b55ad8f29c961cb2b9083 (diff)
refactor: rename status.sh to statusbar
Diffstat (limited to 'bin/statusbar')
-rwxr-xr-xbin/statusbar52
1 files changed, 52 insertions, 0 deletions
diff --git a/bin/statusbar b/bin/statusbar
new file mode 100755
index 0000000..aead5aa
--- /dev/null
+++ b/bin/statusbar
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+set -eu
+
+volume() {
+ volume=$(pactl get-sink-volume @DEFAULT_SINK@ \
+ | awk 'match($0, /\d+%/) { print substr($0, RSTART, RLENGTH-1) }')
+ if [ "$volume" -eq 0 ]; then
+ volume_symbol=""
+ elif [ "$volume" -le 50 ]; then
+ volume_symbol=""
+ else
+ volume_symbol=""
+ fi
+ echo "<span foreground=\"#ed8796\">$volume_symbol $volume%</span>"
+}
+
+network() {
+ ssid=$(iwgetid -r)
+ if [ -n "$ssid" ]; then
+ symbol="直"
+ else
+ symbol="睊"
+ fi
+ echo "<span foreground=\"#f5a97f\">$symbol $ssid</span>"
+}
+
+brightness() {
+ echo "<span foreground=\"#eed49f\"> $(brightnessctl -m | awk -F, '{ print $4 }')</span>"
+}
+
+battery() {
+ status=$(cat /sys/class/power_supply/BAT0/status)
+ capacity=$(cat /sys/class/power_supply/BAT0/capacity)
+
+ idx=$(( ($capacity - 1) / 10 ))
+ case "$status" in
+ "Discharging") symbol=$(echo "<span foreground=\"#ed8796\">󰂃</span>,,,,,,,,," | awk -F, "{ print \$$idx }" ) ;;
+ "Charging" ) symbol=$(echo "         " | awk "{ print \$$idx }" ) ;;
+ "Full" ) symbol="" ;;
+ esac
+ echo "<span foreground=\"#a6da95\">$symbol $capacity%</span>"
+}
+
+clock() {
+ echo "<span foreground=\"#7dc4e4\"> $(date '+%b %d %H:%M')</span>"
+}
+
+while true; do
+ somebar -c status "$(volume) | $(network) | $(brightness) | $(battery) | $(clock)" || true
+ sleep 0.2
+done