Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Oh My Zsh
Commits
49c423c7
Commit
49c423c7
authored
Oct 09, 2019
by
927589452
Committed by
Marc Cornellà
Oct 09, 2019
Browse files
battery: add support for sysctl in FreeBSD (#8155)
parent
c5b4613b
Changes
1
Hide whitespace changes
Inline
Side-by-side
plugins/battery/battery.plugin.zsh
View file @
49c423c7
...
@@ -7,6 +7,9 @@
...
@@ -7,6 +7,9 @@
# Email: neuralsandwich@gmail.com #
# Email: neuralsandwich@gmail.com #
# Modified to add support for Apple Mac #
# Modified to add support for Apple Mac #
###########################################
###########################################
# Author: J (927589452) #
# Modified to add support for FreeBSD #
###########################################
if
[[
"
$OSTYPE
"
=
darwin
*
]]
;
then
if
[[
"
$OSTYPE
"
=
darwin
*
]]
;
then
...
@@ -64,6 +67,52 @@ if [[ "$OSTYPE" = darwin* ]] ; then
...
@@ -64,6 +67,52 @@ if [[ "$OSTYPE" = darwin* ]] ; then
[[
$(
ioreg
-rc
"AppleSmartBattery"
|
grep
'^.*"IsCharging"\ =\ '
|
sed
-e
's/^.*"IsCharging"\ =\ //'
)
==
"Yes"
]]
[[
$(
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
elif
[[
"
$OSTYPE
"
=
linux
*
]]
;
then
function
battery_is_charging
()
{
function
battery_is_charging
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment