diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2023-01-21 19:27:47 +0100 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2023-01-21 19:28:13 +0100 |
| commit | 8857ba84fcd95840d96725a2a43579d3492e8e3c (patch) | |
| tree | ec8bf54d9d14f8c4e6a64ba016f925ea378297b4 /shell-scripts | |
| parent | d53cd97a278566a0ac2c81bb3d4381597709ef55 (diff) | |
add: git ignores
Diffstat (limited to 'shell-scripts')
| -rw-r--r-- | shell-scripts/spectrwmbar | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/shell-scripts/spectrwmbar b/shell-scripts/spectrwmbar new file mode 100644 index 0000000..a106b01 --- /dev/null +++ b/shell-scripts/spectrwmbar @@ -0,0 +1,59 @@ +#!/usr/bin/env sh +# script for spectrwm status bar + +trap 'update' 5 + +fgcolors=("+@fg=1;" "+@fg=2;" "+@fg=3;" "+@fg=4;" "+@fg=5;" "+@fg=6;" "+@fg=7;" "+@fg=8;") +nfgcolors=${#fgcolors[@]} + +SLEEP_SEC=5m + +repeat() { + i=0; while [ $i -lt $1 ] + do + echo -ne "$TOKEN" + i=$(( i + 1 )) + done +} + +cpu() { + read cpu a b c previdle rest < /proc/stat + prevtotal=$((a+b+c+previdle)) + sleep 0.5 + read cpu a b c idle rest < /proc/stat + total=$((a+b+c+idle)) + cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) )) + echo -e "CPU: $cpu%" +} + +battery() { + BATTERY="$(cat /sys/class/power_supply/BAT0/capacity)" + + BAR_LEFT=$BATTERY + BATTERY_BAR="" + BLOCK=$(( 100 / nfgcolors )) + TOKEN=$(printf '\u2588') + + BAT_COL=$(( $nfgcolors -1 )) + #loops forever outputting a line every SLEEP_SEC secs + while [ $(( BAR_LEFT - BLOCK )) -gt 0 ] + do + BATTERY_BAR="${fgcolors[$BAT_COL]}$(repeat $BLOCK)${BATTERY_BAR}" + BAR_LEFT=$(( BAR_LEFT - BLOCK )) + BAT_COL=$(( BAT_COL - 1)) + done + + BATTERY_BAR="BATTERY: ${fgcolors[$BAT_COL]}$(repeat $BAR_LEFT)${BATTERY_BAR}" + echo $BATTERY_BAR +} + +update() { + echo "$(cpu) $(battery)" + wait +} + +while :; do + update + sleep $SLEEP_SEC & + wait +done |
