From cf0972fe4b73a55f9e8c19d5565fa21470862cd9 Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Sun, 16 Apr 2023 18:02:47 -0500 Subject: refactor: rename status.sh to statusbar --- bin/statusbar | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 bin/statusbar (limited to 'bin/statusbar') 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 "$volume_symbol $volume%" +} + +network() { + ssid=$(iwgetid -r) + if [ -n "$ssid" ]; then + symbol="直" + else + symbol="睊" + fi + echo "$symbol $ssid" +} + +brightness() { + echo " $(brightnessctl -m | awk -F, '{ print $4 }')" +} + +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 "󰂃,,,,,,,,," | awk -F, "{ print \$$idx }" ) ;; + "Charging" ) symbol=$(echo "         " | awk "{ print \$$idx }" ) ;; + "Full" ) symbol="" ;; + esac + echo "$symbol $capacity%" +} + +clock() { + echo " $(date '+%b %d %H:%M')" +} + +while true; do + somebar -c status "$(volume) | $(network) | $(brightness) | $(battery) | $(clock)" || true + sleep 0.2 +done -- cgit v1.2.3