commit ea1181e3d667cc70ce5d7f7e58ee8f989207ae0d Author: Michael Peters Date: Sat Apr 29 12:35:05 2023 -0700 initial commit diff --git a/battery.sh b/battery.sh new file mode 100755 index 0000000..d6cb5c8 --- /dev/null +++ b/battery.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +charge_now=$(cat /sys/class/power_supply/BAT0/charge_now) +charge_full=$(cat /sys/class/power_supply/BAT0/charge_full) + +# https://github.com/torvalds/linux/blob/7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf/Documentation/ABI/testing/sysfs-class-power +# line 463 +# Unknown, Full, Charging, Discharging, Not charging +stat=$(cat /sys/class/power_supply/BAT0/status) + + +stat_symbol="" + +bat_stat_symbol () { + # charge as an integer between 0-10 + charge=$((10 * $charge_now / $charge_full)) + case $charge in + 0) stat_symbol="" ;; + 1) stat_symbol="" ;; + 2) stat_symbol="" ;; + 3) stat_symbol="" ;; + 4) stat_symbol="" ;; + 5) stat_symbol="" ;; + 6) stat_symbol="" ;; + 7) stat_symbol="" ;; + 8) stat_symbol="" ;; + 9) stat_symbol="" ;; + 10) stat_symbol="" ;; + esac +} + +case $stat in + 'Full') stat_symbol="" ;; + 'Charging') stat_symbol="" ;; + 'Discharging') bat_stat_symbol ;; + 'Not charging') bat_stat_symbol ;; + 'Unknown') stat_symbol="" ;; + *) stat_symbol="" ;; +esac + +charge_pct=$((100 * $charge_now / $charge_full)) +if [[ $charge_pct == 100 ]]; then + charge_txt='100' +else + charge_txt=$(printf "%d%%" $charge_pct) +fi + +printf "%s %s\n" $stat_symbol $charge_txt diff --git a/cpu-temp.sh b/cpu-temp.sh new file mode 100755 index 0000000..89f7461 --- /dev/null +++ b/cpu-temp.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +sensors | awk '/Core 0/ {print $3}' + diff --git a/cpu-use.sh b/cpu-use.sh new file mode 100755 index 0000000..8c80fce --- /dev/null +++ b/cpu-use.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# See https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/statusbar/sb-cpubars#L9 + +cache=/tmp/cpubarscache + +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" +old=$(cat "$cache") +printf " " +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" + diff --git a/datetime.sh b/datetime.sh new file mode 100755 index 0000000..3c631c9 --- /dev/null +++ b/datetime.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Time Icon +hour_12="$(date '+%I')" +hour_12_icon=" " +case $hour_12 in + "01") hour_12_icon=" " ;; + "02") hour_12_icon=" " ;; + "03") hour_12_icon=" " ;; + "04") hour_12_icon=" " ;; + "05") hour_12_icon=" " ;; + "06") hour_12_icon=" " ;; + "07") hour_12_icon=" " ;; + "08") hour_12_icon=" " ;; + "09") hour_12_icon=" " ;; + "10") hour_12_icon=" " ;; + "11") hour_12_icon=" " ;; + "12") hour_12_icon=" " ;; +esac + +printf "$hour_12_icon$(date '+%R')  $(date '+%b %d, %Y')\n" + diff --git a/net-rate.sh b/net-rate.sh new file mode 100755 index 0000000..c96d4f6 --- /dev/null +++ b/net-rate.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# See Luke Smith's Stuff +# https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/statusbar/sb-nettraf + +# Returns the change in the value since the last time it was run +update() { + sum=0 + for arg; do + read -r i < "$arg" + sum=$(( sum + i )) + done + #cache='/dev/shm/net-rate-log' + cache=${XDG_CACHE_HOME:-$HOME/.cache}/${1##*/} + [ -f "$cache" ] && read -r old < "$cache" || old=0 + printf %d\\n "$sum" > "$cache" + printf %d\\n $(( sum - old )) +} + +# bytes since this script was last run +rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) +tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) + +# the interval (in seconds) this script is running at +interval=5 + +# bytes / interval = bytes per-second +rx_s=$(($rx / $interval)) +tx_s=$(($tx / $interval)) + +# Human-Readable (e.g. 24M) +rx_sh="$(numfmt --to=iec $rx_s)" +tx_sh="$(numfmt --to=iec $tx_s)" + +# 2M/s is high download +high_down_sec=$((2 * 1024 * 1024)) + +# 64K/s is high upload +high_up_sec=$((64 * 1024)) + +if [ $rx_s -gt $high_down_sec ] +then + down_icon='' +else + down_icon='' +fi + +if [ $tx_s -gt $high_up_sec ] +then + up_icon='' +else + up_icon='' +fi + +printf "%4s%s %4s%s\n" $rx_sh $down_icon $tx_sh $up_icon + diff --git a/ram-free.sh b/ram-free.sh new file mode 100755 index 0000000..5803a8f --- /dev/null +++ b/ram-free.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# See Luke Smith's sb-memory +#https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/statusbar/sb-memory + +#free --mebi | sed -n '2{p;q}' | awk '{printf (" %2.2fG/%2.2fG\n", ( $3 / 1000), ($2 / 1000))}' +free --mebi | sed -n '2{p;q}' | awk '{printf (" %2.2fG\n", ( $3 / 1024))}' diff --git a/volume.sh b/volume.sh new file mode 100755 index 0000000..8b27e48 --- /dev/null +++ b/volume.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +muted="$(pamixer --get-mute)" +if [ $muted != "false" ] +then + printf "ﱝ " +else + volume="$(pamixer --get-volume)" + if [ $volume -gt 30 ] + then + printf "墳 $volume%%\n" + elif [ $volume -gt 10 ] + then + printf "奔 $volume%%\n" + else + printf "奄 $volume%%\n" + fi +fi +