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
7290a08b
Commit
7290a08b
authored
5 years ago
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
battery: fix floating point output in macOS
Fixes #8676
parent
0e571427
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
15 deletions
+17
-15
battery.plugin.zsh
plugins/battery/battery.plugin.zsh
+17
-15
No files found.
plugins/battery/battery.plugin.zsh
View file @
7290a08b
...
...
@@ -21,7 +21,8 @@ if [[ "$OSTYPE" = darwin* ]]; then
local
smart_battery_status
=
"
$(
ioreg
-rc
AppleSmartBattery
)
"
local
-F
maxcapacity
=
$(
command grep
'^.*"MaxCapacity"\ =\ '
<<<
$smart_battery_status
|
sed
-e
's/^.*"MaxCapacity"\ =\ //'
)
local
-F
currentcapacity
=
$(
command grep
'^.*"CurrentCapacity"\ =\ '
<<<
$smart_battery_status
|
sed
-e
's/^.*CurrentCapacity"\ =\ //'
)
echo
$((
(
currentcapacity/maxcapacity
)
*
100
))
local
-i
pct
=
$((
(
currentcapacity/maxcapacity
)
*
100
))
echo
$pct
}
function
battery_pct_remaining
()
{
...
...
@@ -47,16 +48,17 @@ if [[ "$OSTYPE" = darwin* ]]; then
}
function
battery_pct_prompt
()
{
local
battery_pct color
if
ioreg
-rc
AppleSmartBattery |
command grep
-q
'^.*"ExternalConnected"\ =\ No'
;
then
b
=
$(
battery_pct_remaining
)
if
[[
$b
-gt
50
]]
;
then
b
attery_pct
=
$(
battery_pct_remaining
)
if
[[
$b
attery_pct
-gt
50
]]
;
then
color
=
'green'
elif
[[
$b
-gt
20
]]
;
then
elif
[[
$b
attery_pct
-gt
20
]]
;
then
color
=
'yellow'
else
color
=
'red'
fi
echo
"%{
$fg
[
$color
]%}[
$
(
battery_pct_remaining
)
%%]%{
$reset_color
%}"
echo
"%{
$fg
[
$color
]%}[
$
{
battery_pct
}
%%]%{
$reset_color
%}"
else
echo
"∞"
fi
...
...
@@ -93,19 +95,19 @@ elif [[ "$OSTYPE" = freebsd* ]]; then
}
function
battery_pct_prompt
()
{
local
b color
b
=
$(
battery_pct_remaining
)
local
b
attery_pct
color
b
attery_pct
=
$(
battery_pct_remaining
)
if
battery_is_charging
;
then
echo
"∞"
else
if
[[
$b
-gt
50
]]
;
then
if
[[
$b
attery_pct
-gt
50
]]
;
then
color
=
'green'
elif
[[
$b
-gt
20
]]
;
then
elif
[[
$b
attery_pct
-gt
20
]]
;
then
color
=
'yellow'
else
color
=
'red'
fi
echo
"%{
$fg
[
$color
]%}
$
(
battery_pct_remaining
)
%%%{
$reset_color
%}"
echo
"%{
$fg
[
$color
]%}
$
{
battery_pct
}
%%%{
$reset_color
%}"
fi
}
...
...
@@ -136,19 +138,19 @@ elif [[ "$OSTYPE" = linux* ]]; then
}
function
battery_pct_prompt
()
{
local
b color
b
=
$(
battery_pct_remaining
)
local
b
attery_pct
color
b
attery_pct
=
$(
battery_pct_remaining
)
if
battery_is_charging
;
then
echo
"∞"
else
if
[[
$b
-gt
50
]]
;
then
if
[[
$b
attery_pct
-gt
50
]]
;
then
color
=
'green'
elif
[[
$b
-gt
20
]]
;
then
elif
[[
$b
attery_pct
-gt
20
]]
;
then
color
=
'yellow'
else
color
=
'red'
fi
echo
"%{
$fg
[
$color
]%}
$
(
battery_pct_remaining
)
%%%{
$reset_color
%}"
echo
"%{
$fg
[
$color
]%}
$
{
battery_pct
}
%%%{
$reset_color
%}"
fi
}
...
...
This diff is collapsed.
Click to expand it.
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