diff options
-rwxr-xr-x | sb-battery | 52 | ||||
-rwxr-xr-x | sb-date | 23 | ||||
-rwxr-xr-x | sb-systemstats | 45 | ||||
-rwxr-xr-x | sb-theme | 28 |
4 files changed, 148 insertions, 0 deletions
diff --git a/sb-battery b/sb-battery new file mode 100755 index 0000000..abfb53c --- /dev/null +++ b/sb-battery @@ -0,0 +1,52 @@ +#!/bin/sh +# Display the current battery status. + +notify() { + dunstify \ + -i battery-good-symbolic \ + -t 4000 \ + -h string:x-canonical-private-synchronous:battery \ + "Battery" "$1" +} + +case "$BLOCK_BUTTON" in + 1) notify "$(acpi -b | awk -F ': |, ' '{printf "%s\n%s\n", $2, $4}')" ;; + 3) ghostty -e "$EDITOR" "$0" ;; +esac + +. sb-theme + +# Loop through all attached batteries. +for battery in /sys/class/power_supply/BAT?*; do + # If non-first battery, print a space separator. + [ -n "${capacity+x}" ] && printf " " + + capacity="$(cat "$battery/capacity" 2>&1)" + if [ "$capacity" -gt 90 ]; then + status=" " + elif [ "$capacity" -gt 60 ]; then + status=" " + elif [ "$capacity" -gt 40 ]; then + status=" " + elif [ "$capacity" -gt 10 ]; then + status=" " + else + status=" " + fi + + case "$(cat "$battery/status" 2>&1)" in + Full) status=" " ;; + Discharging) + if [ "$capacity" -le 20 ]; then + status="$status" + color=1 + fi + ;; + Charging) status="$status" ;; + "Not charging") status=" " ;; + Unknown) status="? $status" ;; + *) exit 1 ;; + esac + + display "$status$capacity%" "$color" +done @@ -0,0 +1,23 @@ +#!/bin/sh +# Display the current time in HH:MM:SS. + +notify() { + notify-send --icon=office-calendar-symbolic \ + --hint=string:x-canonical-private-synchronous:"$1" "$@" +} + +case $BLOCK_BUTTON in + 3) + notify "This Month" "$(cal --color=always | + sed "s|..7m|<span color='$(xrdb -get color1)'>|;s|..0m|</span>|")" + appointments="$(calcurse -d1 \ + --format-apt "• <i>%S - %E</i>\n <span foreground='$(xrdb -get color7)'>%m</span>\n" \ + --format-event "• <span foreground='$(xrdb -get color15)'>%m</span>\n")" + [ -n "$appointments" ] && notify "Appointments" "$appointments" + ;; + 2) setsid --fork terminal -e calcurse ;; + 1) dunstify "This Month" "$(cal --color=always)";; +esac + +. sb-theme +display " $(date '+%a %d %b %T')" diff --git a/sb-systemstats b/sb-systemstats new file mode 100755 index 0000000..0f69661 --- /dev/null +++ b/sb-systemstats @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +CPU_TEMP=$(sensors | awk ' + /^Tdie|^Package id|^Core 0|^CPU|^temp1/ { + gsub(/[+°C]/, ""); + for (i=1; i<=NF; i++) { + if ($i ~ /^[0-9]+(\.[0-9]+)?$/) { + gsub(/\..*/, "", $i); + print $i; + exit; + } + } + }') + +# Debug CPU temperature detection, if not found, return N/A +if [ -z "$CPU_TEMP" ]; then + # Try simpler pattern as fallback + CPU_TEMP=$(sensors | grep -E '^(Core 0|Package id 0|CPU)' | awk '{print $3}' | tr -d '+°C' | head -n1) +fi + +[ -z "$CPU_TEMP" ] && CPU_TEMP="N/A" + + +# Try different fan sensors +FAN_SPEED=$(sensors | awk '/^fan|^cpu_fan/ {print $2}') +[ -z "$FAN_SPEED" ] && FAN_SPEED="N/A" + + +# Show warning icon if CPU temp is high +case $CPU_TEMP in + "N/A") COLOR="#d8dee9" && CPU_ICON=" ?" ;; + [7-9][6-9]|[8-9][0-9]|100) COLOR="#bf616a" && CPU_ICON="" ;; # Greater than 75 + [6][6-9]|7[0-5]) COLOR="#ebcb8b" && CPU_ICON="" ;; # Between 66 and 75 + *) COLOR="#a3be8c" && CPU_ICON="" ;; # 65 or below +esac + +# Send to bar +echo " $FAN_SPEED $CPU_TEMP°C" + +# Clicking on bar +case $BLOCK_BUTTON in + 1) notify-send "$(sensors)";; + 2) notify-send "button 2 clicked";; + 3) notify-send "button 3 clicked";; +esac diff --git a/sb-theme b/sb-theme new file mode 100755 index 0000000..f04c205 --- /dev/null +++ b/sb-theme @@ -0,0 +1,28 @@ +#!/bin/sh +# Utility functions for theming statusbar scripts. + +display() { + if [ -n "$2" ]; then + color="$2" + else + case "$(basename "$0")" in + sb-mail) color=13 ;; + sb-music) color=14 ;; + sb-disk) color=10 ;; + sb-memory) color=15 ;; + sb-loadavg) color=11 ;; + sb-mic) color=9 ;; + sb-record) color=9 ;; + sb-volume) color=15 ;; + sb-battery) color=14 ;; + sb-date) color=12 ;; + sb-network) color=9 ;; + *) color=15 ;; + esac + fi + + case "$STATUSBAR" in + dwmblocks) echo "^C$color^$1" ;; + *) echo "$1" ;; + esac +} |