dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 857ad54ad7599cb58949681113d025d18211f81c
parent 484b9ab92ac61871aa2c6707e862c6c557716736
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Wed,  5 May 2021 18:01:13 +0200

Add CPU script for dwmblocks

Diffstat:
Mscripts/dwmblock-battery | 23+++++++++++++++--------
Mscripts/dwmblock-brightness | 10++++++----
Ascripts/dwmblock-cpu | 38++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 12 deletions(-)

diff --git a/scripts/dwmblock-battery b/scripts/dwmblock-battery @@ -2,11 +2,18 @@ case "$BUTTON" in 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -printf "%s%%\n" "$(battery | tac | tr -d '\n' | sed ' - s/Charging/⚡/; - /Discharging[01]*[0-9]$/s/Discharging/‼ /; - s/Discharging/🔋 /; - s/Not charging/⛔/; - s/Full/✅/; - s/Unknown/‽‽/' \ - | tac | tr -d '\n')" + +status="$(battery | tac | tr -d '\n' | sed ' + s/Charging/⚡/; + /Discharging[01]*[0-9]$/s/Discharging/‼ /; + s/Discharging/🔋 /; + s/Not charging/⛔/; + s/Full/✅/; + s/Unknown/‽‽/' \ + | tac | tr -d '\n')" + +case "$status" in + ‼*) notify "Battery low" "$status%" battery critical;; + ✅*) notify "Battery charged" "$status%" battery;; +esac +printf "%s%%\n" "$status" diff --git a/scripts/dwmblock-brightness b/scripts/dwmblock-brightness @@ -1,16 +1,18 @@ #!/bin/sh case "$BUTTON" in - 1) "$TERMINAL" -e backlight-brightness ;; + 1) + pgrep -f backlight-brightness || setsid -f "$TERMINAL" -e backlight-brightness + pkill -RTMIN+3 dwmblocks;; 3) backlight-brightness -s 100 ;; 4) backlight-brightness '-10' - pkill -RTMIN+1 dwmblocks + pkill -RTMIN+3 dwmblocks ;; 5) backlight-brightness '+20' - pkill -RTMIN+1 dwmblocks + pkill -RTMIN+3 dwmblocks ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -paste -d '/' /sys/class/backlight/*/brightness /sys/class/backlight/*/max_brightness +paste -d '/' /sys/class/backlight/*/actual_brightness /sys/class/backlight/*/max_brightness diff --git a/scripts/dwmblock-cpu b/scripts/dwmblock-cpu @@ -0,0 +1,38 @@ +#!/bin/sh +# Cache in tmpfs to improve speed and reduce SSD load +cache=/tmp/cpubarscache + +case "$BUTTON" in + 1) pgrep -f htop || setsid -f "$TERMINAL" -e htop ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# id total idle +stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat) +[ ! -f $cache ] && echo "$stats" > "$cache" && exit + +old=$(cat "$cache") +printf "CPU " + +echo "$stats" | while read -r row; do + id=${row%% *} + rest=${row#* } + total=${rest%% *} + idle=${rest##* } + + case "$(echo "$old" | awk '{if ($1 == id) + printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ + id="$id" total="$total" idle="$idle")" in + + "0") printf "▁";; + "1") printf "▂";; + "2") printf "▃";; + "3") printf "▄";; + "4") printf "▅";; + "5") printf "▆";; + "6") printf "▇";; + "7") printf "█";; + "8") printf "█";; + esac +done; printf "\\n" +echo "$stats" > "$cache"