diff options
author | Vikas Kushwaha <dev@vikas.rocks> | 2024-11-21 13:30:52 +0530 |
---|---|---|
committer | Vikas Kushwaha <dev@vikas.rocks> | 2024-11-21 13:30:52 +0530 |
commit | 5c916d69d457101326803eb076a746060e3618cf (patch) | |
tree | d6fce3256eede1c1bf78fb6a1be75b9cc4b84cee /.local/bin/statusbar/i3battery |
Moved from github
Diffstat (limited to '.local/bin/statusbar/i3battery')
-rwxr-xr-x | .local/bin/statusbar/i3battery | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/.local/bin/statusbar/i3battery b/.local/bin/statusbar/i3battery new file mode 100755 index 0000000..5b2fb15 --- /dev/null +++ b/.local/bin/statusbar/i3battery @@ -0,0 +1,66 @@ +#!/bin/sh + +case "$BLOCK_BUTTON" in + 1) notify-send Temprature "$(sensors --no-adapter coretemp-isa-0000 | + tail +2 | sed "s|(.*)||")" ;; + 2) $TERMINAL -e "$EDITOR" "$0" ;; + 3) $TERMINAL -e battop ;; + 4) brightness up ;; + 5) brightness down ;; +esac; + +# Loop through all attached batteries and format the info +for battery in /sys/class/power_supply/BAT?*; do + capacity="$(cat "$battery/capacity" 2>&1)" + # If non-first battery, print a space separator. + # [ -n "${capacity+x}" ] && printf " " + # Sets up the status and capacity + status="$(cat "$battery/status" 2>&1)" + case "$status" in + "Full") icon="" ;; + "Discharging") case "$capacity" in + 9[0-9]) icon="" ;; + 8[0-9]) icon="" ;; + 7[0-9]) icon="" ;; + 6[0-9]) icon="" ;; + 5[0-9]) icon="" ;; + 4[0-9]) icon="" ;; + 3[0-9]) icon="" ;; + 2[0-9]) icon="" ;; + 1[0-9]|[0-9]) icon="" ;; + 100) icon="" ;; + esac ;; + "Charging") case "$capacity" in + 9[0-9]) icon="" ;; + 8[0-9]) icon="" ;; + 7[0-9]) icon="" ;; + 6[0-9]) icon="" ;; + 5[0-9]) icon="" ;; + 4[0-9]) icon="" ;; + 3[0-9]) icon="" ;; + 2[0-9]) icon="" ;; + 1[0-9]|[0-9]) icon="" ;; + 100) icon="" ;; + esac ;; + "Not charging") icon="" ;; + "Unknown") icon="" ;; + *) exit 1 ;; + esac + # Will make a warn variable if discharging and low + [ "$status" = "Discharging" ] && [ "$capacity" -le 25 ] && warn="❗" + # Prints the info + printf "%s%s %d%%" "$warn" "$icon" "$capacity"; unset warn +done && printf "\\n" + +echo +if [ $capacity -ge 80 ]; then + echo "$BLOCK_COLOR_LEVEL1" +elif [ $capacity -ge 40 ]; then + echo "$BLOCK_COLOR_LEVEL2" +elif [ $capacity -ge 20 ]; then + echo "$BLOCK_COLOR_LEVEL3" +elif [ $capacity -ge 10 ]; then + echo "$BLOCK_COLOR_LEVEL4" +else + echo "$BLOCK_COLOR_LEVEL5" +fi |