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
39e61614
Commit
39e61614
authored
Feb 11, 2020
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up Linux battery commands and syntax
parent
1bd7a7ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
battery.plugin.zsh
plugins/battery/battery.plugin.zsh
+10
-10
No files found.
plugins/battery/battery.plugin.zsh
View file @
39e61614
...
...
@@ -116,17 +116,17 @@ elif [[ "$OSTYPE" = freebsd* ]] ; then
elif
[[
"
$OSTYPE
"
=
linux
*
]]
;
then
function
battery_is_charging
()
{
!
[[
$(
acpi 2>/dev/null |
grep
-c
'^Battery.*Discharging'
)
-gt
0
]]
!
acpi 2>/dev/null |
command grep
-q
'^Battery.*Discharging'
}
function
battery_pct
()
{
if
((
$+
commands[acpi]
))
;
then
echo
"
$(
acpi 2>/dev/null |
cut
-f2
-d
','
|
tr
-cd
'[:digit:]'
)
"
acpi 2>/dev/null |
cut
-f2
-d
','
|
tr
-cd
'[:digit:]'
fi
}
function
battery_pct_remaining
()
{
if
[
!
$(
battery_is_charging
)
]
;
then
if
!
battery_is_charging
;
then
battery_pct
else
echo
"External Power"
...
...
@@ -134,15 +134,17 @@ elif [[ "$OSTYPE" = linux* ]] ; then
}
function
battery_time_remaining
()
{
if
[[
$(
acpi 2>/dev/null |
grep
-c
'^Battery.*Discharging'
)
-gt
0
]]
;
then
echo
$(
acpi 2>/dev/null |
cut
-f3
-d
','
)
if
!
battery_is_charging
;
then
acpi 2>/dev/null |
cut
-f3
-d
','
fi
}
function
battery_pct_prompt
()
{
b
=
$(
battery_pct_remaining
)
if
[[
$(
acpi 2>/dev/null |
grep
-c
'^Battery.*Discharging'
)
-gt
0
]]
;
then
if
[
$b
-gt
50
]
;
then
local
b
=
$(
battery_pct_remaining
)
if
battery_is_charging
;
then
echo
"∞"
else
if
[[
$b
-gt
50
]]
;
then
color
=
'green'
elif
[
$b
-gt
20
]
;
then
color
=
'yellow'
...
...
@@ -150,8 +152,6 @@ elif [[ "$OSTYPE" = linux* ]] ; then
color
=
'red'
fi
echo
"%{
$fg
[
$color
]%}
$(
battery_pct_remaining
)
%%%{
$reset_color
%}"
else
echo
"∞"
fi
}
...
...
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