summaryrefslogtreecommitdiff
path: root/bin/statusline.sh
diff options
context:
space:
mode:
authorSam Nystrom <sam@samnystrom.dev>2024-10-15 13:29:10 -0400
committerSam Nystrom <sam@samnystrom.dev>2024-10-15 13:29:10 -0400
commit2c98bbacc8db3b251e1679f9da84cf1f5ed5726a (patch)
tree10d44c9b82d275d66d880ff8ec33992cddda12b5 /bin/statusline.sh
parentc8c79e6c6a5c4bb1e0ba44f309ce5ae612f97e1c (diff)
update ~/bin
Diffstat (limited to 'bin/statusline.sh')
-rwxr-xr-xbin/statusline.sh79
1 files changed, 79 insertions, 0 deletions
diff --git a/bin/statusline.sh b/bin/statusline.sh
new file mode 100755
index 0000000..61eb799
--- /dev/null
+++ b/bin/statusline.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+volume() {
+ volume="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)"
+ volume="$(dc -e "${volume#Volume:\ } 100 * p")"
+ volume="${volume%.*}"
+ if [ "$volume" -eq 0 ]; then
+ symbol=
+ elif [ "$volume" -le 50 ]; then
+ symbol=
+ else
+ symbol=
+ fi
+ printf '%s %d%%' "$symbol" "$volume"
+}
+
+network() {
+ ssid="$(iwctl station wlan0 get-networks | awk -F' ' '/>/{print $3}')"
+ if [ -n "$ssid" ]; then
+ printf '󰖩 %s' "$ssid"
+ else
+ printf '󰖪 '
+ fi
+}
+
+brightness() {
+ printf ' %d%%' "$(brightctl)"
+}
+
+battery() {
+ cap="$(cat /sys/class/power_supply/BAT0/capacity)"
+ stat="$(cat /sys/class/power_supply/BAT0/status)"
+
+ symbol=󰁹
+ index=$(((cap-1)/10+1))
+ case "$stat" in
+ Discharging)
+ symbol="$(printf '󰂃 󰁻 󰁼 󰁽 󰁾 󰁿 󰂀 󰂁 󰂂 󰁹' | cut -d' ' -f$index)"
+ ;;
+ Charging)
+ symbol="$(printf '󰢜 󰂆 󰂇 󰂈 󰢝 󰂉 󰢞 󰂊 󰂋 󰂅' | cut -d' ' -f$index)"
+ ;;
+ Full)
+ symbol=󰂄
+ ;;
+ esac
+ printf '%s %d%%' "$symbol" "$cap"
+}
+
+clock() {
+ printf ' %s' "$(date '+%b %-d %H:%M:%S')"
+}
+
+# Make the volume and brightness sections appear to update in real time by
+# polling more frequently when the user is changing them.
+last_vol=
+last_brt=
+sleep_for=10
+while true; do
+ vol="$(volume)"
+ brt="$(brightness)"
+ if [ "$last_vol" != "$vol" ] || [ "$last_brt" != "$brt" ]; then
+ sleep_for=1
+ elif [ $sleep_for != 10 ]; then
+ sleep_for=$((sleep_for+1))
+ else
+ sleep_for=10
+ fi
+ last_vol="$vol"
+ last_brt="$brt"
+
+ printf '%s | %s | %s | %s | %s\n' \
+ "$vol" \
+ "$(network)" \
+ "$brt" \
+ "$(battery)" \
+ "$(clock)"
+ sleep $((sleep_for/10)).$((sleep_for%10))
+done