summaryrefslogtreecommitdiff
path: root/plugins/battery
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2019-10-09 20:16:18 -0600
committerTuowen Zhao <ztuowen@gmail.com>2019-10-09 20:16:18 -0600
commit112a85697481cae663ff281b74fdc1f72a67b294 (patch)
treee7f6f938fda886c87d296711d853bcc9833b9ec2 /plugins/battery
parent09829ba30c269e35bddf44a21f3357efd31e686f (diff)
parent710a3d5a1e2888a4dfb1769f8f1edd8a590eee22 (diff)
downloadzsh-112a85697481cae663ff281b74fdc1f72a67b294.tar.gz
zsh-112a85697481cae663ff281b74fdc1f72a67b294.tar.bz2
zsh-112a85697481cae663ff281b74fdc1f72a67b294.zip
Merge branch 'master' of https://github.com/robbyrussell/oh-my-zsh
Diffstat (limited to 'plugins/battery')
-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() {