aboutsummaryrefslogtreecommitdiffstats
path: root/basics/.local/bin/statusbar
diff options
context:
space:
mode:
Diffstat (limited to 'basics/.local/bin/statusbar')
-rwxr-xr-xbasics/.local/bin/statusbar/battery30
-rwxr-xr-xbasics/.local/bin/statusbar/memory22
2 files changed, 52 insertions, 0 deletions
diff --git a/basics/.local/bin/statusbar/battery b/basics/.local/bin/statusbar/battery
new file mode 100755
index 0000000..da6dd12
--- /dev/null
+++ b/basics/.local/bin/statusbar/battery
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+battery_path='/sys/class/power_supply/BAT0'
+
+percentage=$(head -n1 "${battery_path}/capacity")
+state=$(head -n1 "${battery_path}/status")
+rate=$([ -f "${battery_path}/current_now" ] &&
+ head -n1 "${battery_path}/current_now" ||
+ head -n1 "${battery_path}/power_now")
+volt=$(head -n1 "${battery_path}/voltage_now")
+now=$([ -f "${battery_path}/charge_now" ] &&
+ head -n1 "${battery_path}/charge_now" ||
+ head -n1 "${battery_path}/energy_now")
+max=$([ -f "${battery_path}/current_full" ] &&
+ head -n1 "${battery_path}/current_full" ||
+ head -n1 "${battery_path}/energy_full")
+cap=$([ "$state" = "Charging" ] &&
+ echo "$max $now" | awk '{printf "%d", $1 - $2}' ||
+ echo "$now")
+
+remaining=$( echo "$cap $volt" | awk '{printf "%f", $1/$2}' )
+current_rate=$( echo "$rate $volt" | awk '{printf "%f", $1/$2}' )
+seconds_remaining=$( [ "${current_rate#0.00}" = "$current_rate" ] &&
+ echo "$remaining $current_rate" |
+ awk '{printf "%d", 3600*$1/$2}' ||
+ echo "0" )
+time_remaining=$( date -ud "@${seconds_remaining}" "+%H:%M:%S" )
+
+# TODO: more variable output with flags?
+echo "$state $percentage $time_remaining"
diff --git a/basics/.local/bin/statusbar/memory b/basics/.local/bin/statusbar/memory
new file mode 100755
index 0000000..7a952d8
--- /dev/null
+++ b/basics/.local/bin/statusbar/memory
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+meminfo=$(awk '
+/^MemTotal:/ {Total=$2*1024}
+/^MemAvailable:/ {Available=$2*1024}
+/^MemFree:/ {Free=$2*1024}
+/^Buffers:/ {Buffers=$2*1024}
+/^Cached:/ {Cached=$2*1024}
+/^SReclaimable:/ {SReclaimable=$2*1024}
+/^Shmem:/ {Shmem=$2*1024}
+END {
+print Total ":" Available ":" Free ":" Buffers ":" Cached ":" SReclaimable ":" Shmem}' /proc/meminfo)
+
+echo "$meminfo" |
+ while IFS=: read -r t a f b c sr sh; do
+ memfree=$(echo "$a $t" | awk '{printf "%.3f", ($1 / $2) * 100}')
+ memused=$(echo "$memfree" | awk '{printf "%.3f", (100 - $1)}')
+
+ # Percentage values
+ # TODO: other values, controllable by flags?
+ echo "$memfree $memused"
+ done