aboutsummaryrefslogtreecommitdiffstats
path: root/basics/.local/bin/battery-monitor
diff options
context:
space:
mode:
authorPeter Son Struschka <me@peter-struschka.com>2020-07-29 16:40:02 +0800
committerPeter Son Struschka <me@peter-struschka.com>2020-07-29 16:48:22 +0800
commita1d6fc2f3e6ab041cc51cb085ac59a646a126d25 (patch)
treeb1ca8b11365cd255dd2f93a47dd0e918e1dae16a /basics/.local/bin/battery-monitor
parent556bbd7fd182937e32eb5320a27ba337ac454be0 (diff)
downloaddotfiles-a1d6fc2f3e6ab041cc51cb085ac59a646a126d25.tar.gz
dotfiles-a1d6fc2f3e6ab041cc51cb085ac59a646a126d25.tar.bz2
dotfiles-a1d6fc2f3e6ab041cc51cb085ac59a646a126d25.tar.lz
dotfiles-a1d6fc2f3e6ab041cc51cb085ac59a646a126d25.tar.xz
dotfiles-a1d6fc2f3e6ab041cc51cb085ac59a646a126d25.tar.zst
dotfiles-a1d6fc2f3e6ab041cc51cb085ac59a646a126d25.zip
basics+bspwm+herbstluftwm+i3wm+meta+polybar+xmonad: wm configs overhaul
Created polybar as its own config instead of duplicated in bspwm and i3's directories allowing them both to be installed. Created herbstluftwm, xmonad window manager configs. Added scripts for a status bar, and fixed scripts.
Diffstat (limited to 'basics/.local/bin/battery-monitor')
-rwxr-xr-xbasics/.local/bin/battery-monitor45
1 files changed, 40 insertions, 5 deletions
diff --git a/basics/.local/bin/battery-monitor b/basics/.local/bin/battery-monitor
index ff1ef8b..1dfa7b6 100755
--- a/basics/.local/bin/battery-monitor
+++ b/basics/.local/bin/battery-monitor
@@ -1,6 +1,41 @@
+#!/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" ] && printf "%d-%d\n" "${max}" "${now}" | bc || echo "${now}")
+
+remaining=$( printf "%d/%d\n" "${cap}" "${volt}" | bc -l )
+current_rate=$( printf "%d/%d\n" "${rate}" "${volt}" | bc -l )
+echo $( [ "${current_rate}" != "0" ] && echo "not zero" || echo "is zero" )
+seconds=$( [ "${current_rate}" != "0" ] && printf "3600*%f/%f\n" "${remaining}" "${current_rate}" | bc || echo "0")
+time_remaining=$( date -ud "@${seconds}" "+%H:%M:%S" )
+
+echo "percentage ${percentage}%"
+echo "state ${state}"
+echo "rate ${rate}"
+echo "volt ${volt}"
+echo "now ${now}"
+echo "max ${max}"
+echo "cap ${cap}"
+echo "remaining ${remaining}"
+echo "current_rate ${current_rate}"
+echo "seconds ${seconds}"
+echo "time ${time_remaining}"
+
+exit 0
+
battery_level=`acpi -b | cut -d ' ' -f 4 | grep -o '[0-9]*'`
+battery_level=$(head -n1 /sys/class/power_supply/BAT0/capacity)
battery_state=$(acpi | grep 'Battery' | sed 's/Battery\s[0-9]*: //' | sed 's/, [0-9][0-9]*\%.*//')
+battery_state=$(head -n1 /sys/class/power_supply/BAT0/status)
battery_remaining=$(acpi | grep -oh '[0-9:]* remaining' | sed 's/:\w\w remaining$/ Minutes/' | sed 's/00://' | sed 's/:/h /')
+kk
if [ ! -f "/tmp/.battery" ]; then
echo "$battery_level" > /tmp/.battery
@@ -18,12 +53,12 @@ checkBatteryLevel() {
exit
fi
- if [ $battery_level -le 3 ]; then
+ if [ $battery_level -le 4 ]; then
sudo systemctl suspend
- elif [ $battery_level -le 5 ]; then
- notify-send "Low Battery" "Your computer will suspend soon unless plugged into a power outlet." -u critical
+ elif [ $battery_level -le 7 ]; then
+ notify-send "Low Battery" "(${time_remaining}) Your computer will suspend soon unless plugged into a power outlet." -u critical
elif [ $battery_level -le 10 ]; then
- notify-send "Low Battery" "${battery_level}% (${battery_remaining}) of battery remaining." -u normal
+ notify-send "Low Battery" "${battery_level}% (${time_remaining}) of battery remaining." -u normal
fi
}
@@ -38,4 +73,4 @@ checkBatteryStateChange() {
}
checkBatteryStateChange
-checkBatteryLevel \ No newline at end of file
+checkBatteryLevel