Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
49c423c7
Commit
49c423c7
authored
Oct 09, 2019
by
927589452
Committed by
Marc Cornellà
Oct 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
battery: add support for sysctl in FreeBSD (#8155)
parent
c5b4613b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
battery.plugin.zsh
plugins/battery/battery.plugin.zsh
+49
-0
No files found.
plugins/battery/battery.plugin.zsh
View file @
49c423c7
...
...
@@ -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
()
{
...
...
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