3e9e385d98da148a7ad8e8d99da35ce6b7aae9ca
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
battery: remove redundant grep calls in battery_pct function
Diff
1diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
2index 857ab6e8c5954c2588ec1cff6b9d927ad639457a..4c4d0d4fccac89546436d5374fded863305330c5 100644
3--- a/plugins/battery/battery.plugin.zsh
4+++ b/plugins/battery/battery.plugin.zsh
5@@ -18,11 +18,10 @@ if [[ "$OSTYPE" = darwin* ]]; then
6 }
7
8 function battery_pct() {
9- local smart_battery_status="$(ioreg -rc AppleSmartBattery)"
10- local -F maxcapacity=$(command grep '^.*"MaxCapacity"\ =\ ' <<< $smart_battery_status | sed -e 's/^.*"MaxCapacity"\ =\ //')
11- local -F currentcapacity=$(command grep '^.*"CurrentCapacity"\ =\ ' <<< $smart_battery_status | sed -e 's/^.*CurrentCapacity"\ =\ //')
12- local -i pct=$(( (currentcapacity/maxcapacity) * 100 ))
13- echo $pct
14+ local battery_status="$(ioreg -rc AppleSmartBattery)"
15+ local -i capacity=$(sed -n -e '/MaxCapacity/s/^.*"MaxCapacity"\ =\ //p' <<< $battery_status)
16+ local -i current=$(sed -n -e '/CurrentCapacity/s/^.*"CurrentCapacity"\ =\ //p' <<< $battery_status)
17+ echo $(( current * 100 / capacity ))
18 }
19
20 function battery_pct_remaining() {