summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author927589452 <927589452@users.noreply.github.com>2019-10-09 19:24:44 +0200
committerMarc Cornellà <marc.cornella@live.com>2019-10-09 19:24:44 +0200
commit49c423c7e0a6d5193b77e60107e7c329da28d987 (patch)
treee86452864f3f3a52dbc97239baba73f452c6a98d
parentc5b4613bf6e1256e56b5451bccce5972a255a58b (diff)
downloadzsh-49c423c7e0a6d5193b77e60107e7c329da28d987.tar.gz
zsh-49c423c7e0a6d5193b77e60107e7c329da28d987.tar.bz2
zsh-49c423c7e0a6d5193b77e60107e7c329da28d987.zip
battery: add support for sysctl in FreeBSD (#8155)
-rw-r--r--plugins/battery/battery.plugin.zsh49
1 files changed, 49 insertions, 0 deletions
diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
index 8f398cfb3..6b6684716 100644
--- a/plugins/battery/battery.plugin.zsh
+++ b/plugins/battery/battery.plugin.zsh
@@ -7,6 +7,9 @@
# Email: neuralsandwich@gmail.com #
# Modified to add support for Apple Mac #
###########################################
+# Author: J (927589452) #
+# Modified to add support for FreeBSD #
+###########################################
if [[ "$OSTYPE" = darwin* ]] ; then
@@ -64,6 +67,52 @@ if [[ "$OSTYPE" = darwin* ]] ; then
[[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"IsCharging"\ =\ ' | sed -e 's/^.*"IsCharging"\ =\ //') == "Yes" ]]
}
+elif [[ "$OSTYPE" = freebsd* ]] ; then
+
+ function battery_is_charging() {
+ [[ $(sysctl -n hw.acpi.battery.state) -eq 2 ]]
+ }
+
+ function battery_pct() {
+ if (( $+commands[sysctl] )) ; then
+ echo "$(sysctl -n hw.acpi.battery.life)"
+ fi
+ }
+
+ function battery_pct_remaining() {
+ if [ ! $(battery_is_charging) ] ; then
+ battery_pct
+ else
+ echo "External Power"
+ fi
+ }
+
+ function battery_time_remaining() {
+ remaining_time=$(sysctl -n hw.acpi.battery.time)
+ if [[ $remaining_time -ge 0 ]] ; then
+ # calculation from https://www.unix.com/shell-programming-and-scripting/23695-convert-minutes-hours-minutes-seconds.html
+ ((hour=$remaining_time/60))
+ ((minute=$remaining_time-$hour*60))
+ echo $hour:$minute
+ fi
+ }
+
+ function battery_pct_prompt() {
+ b=$(battery_pct_remaining)
+ if [ ! $(battery_is_charging) ] ; then
+ if [ $b -gt 50 ] ; then
+ color='green'
+ elif [ $b -gt 20 ] ; then
+ color='yellow'
+ else
+ color='red'
+ fi
+ echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}"
+ else
+ echo "∞"
+ fi
+ }
+
elif [[ "$OSTYPE" = linux* ]] ; then
function battery_is_charging() {