diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-17 10:40:11 -0700 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-10-17 10:40:11 -0700 |
| commit | ea127689e0ae2d39b49004be605e541ff80e2621 (patch) | |
| tree | abbe79e5e37792bd8ebea8f9ac788ff5b8aed704 /.config/lemonbar-xft | |
| download | openbsd-dotfiles-ea127689e0ae2d39b49004be605e541ff80e2621.zip | |
Initial Commit
Diffstat (limited to '.config/lemonbar-xft')
| -rwxr-xr-x | .config/lemonbar-xft/bar.sh | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/.config/lemonbar-xft/bar.sh b/.config/lemonbar-xft/bar.sh new file mode 100755 index 0000000..6aad4b8 --- /dev/null +++ b/.config/lemonbar-xft/bar.sh @@ -0,0 +1,120 @@ +#!/bin/sh +set -o errexit + +RED="%{F#cd0000}" +YELLOW="%{F#cdcd00}" +RESET="%{F-}" + +main() { + while true; do + update_bar + sleep 5 + done +} + +update_bar() { + printf "%%{l} %s | %s | %s | %s | %s %%{r} %s | %s | %s \n" \ + "$(battery)" \ + "$(temp)" \ + "$(cpu)" \ + "$(memory)" \ + "$(brightness)" \ + "$(volume)" \ + "$(wifi)" \ + "$(datetime)" +} + +battery() { + apm_output=$(apm -al) + percent=$(echo "$apm_output" | sed -n '1p') + batt_state=$(echo "$apm_output" | sed -n '2p') + minutes=$(apm -m) + + filled=$((percent / 10)) + bar="" + i=0 + while [ $i -lt 10 ]; do + if [ $i -lt $filled ]; then + if [ "$batt_state" = "1" ]; then + bar="${bar}+" + else + bar="${bar}#" + fi + else + bar="${bar}-" + fi + i=$((i + 1)) + done + + if [ "$percent" -lt 30 ] && [ "$batt_state" != "1" ]; then + bar="${RED}${bar}${RESET}" + elif [ "$percent" -lt 50 ] && [ "$batt_state" != "1" ]; then + bar="${YELLOW}${bar}${RESET}" + fi + + printf "%s%% %s (%s min)" "$percent" "$bar" "$minutes" +} + +temp() { + avg=$(sysctl hw.sensors | awk -F'=' '/temp/ { + gsub(/degC.*/, "", $2); + sum += $2; + count++ + } END { + printf "%.0f", sum/count + }') + + if [ "$avg" -ge 85 ]; then + printf "%s%d°C%s" "$RED" "$avg" "$RESET" + else + printf "%d°C" "$avg" + fi +} + +cpu() { + apm -Pv | awk '{gsub(/\(|\)/, ""); print $5, $6, $4}' +} + +memory() { + top -n | awk '/^Memory:/ { + split($3, r, "/"); + printf "Used:%s Free:%s", r[2], $6 + }' +} + +net() { + ifconfig egress 2>/dev/null | awk '/inet / {print $2}' +} + +brightness() { + bright=$(xbacklight -get | cut -d. -f1) + printf "Bri: %d%%" "$bright" +} + +volume() { + vol=$(sndioctl -n output.level) + percent=$(printf "%.0f" "$(echo "$vol" | awk '{print $1 * 100}')") + + if sndioctl output.mute | grep -q "=1"; then + printf "Vol: MUTE" + else + printf "Vol: %d%%" "$percent" + fi +} + +wifi() { + wifi_info=$(ifconfig iwx0 2>/dev/null | grep "ieee80211:") + if [ -n "$wifi_info" ]; then + ssid=$(echo "$wifi_info" | sed -n 's/.*join \(.*\) chan.*/\1/p' | tr -d '"') + signal=$(ifconfig iwx0 | awk '/ieee80211:/ {for(i=1;i<=NF;i++) if($i ~ /%/) print $i}' | head -1) + printf "%s %s %s" "$ssid" "$signal" "$(net)" + else + net + fi +} + +datetime() { + date '+%Y-%m-%d %H:%M' +} + +main |