Conversation
Hi @ratijas ! Thank you very much for your PR, and sorry for the delay. We've done quite some work on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ratijas ! Thanks for taking the time to put up this PR. I left a few comments.
local raw_data="$(wmic Path Win32_Battery Get /format:list | tr -d '\r' | sed -n '/=./p')" | ||
|
||
# type bat_percent: percent as int in range 0..100 | ||
local bat_percent="$(echo "$raw_data" | grep "EstimatedChargeRemaining" | cut -d = -f 2)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local bat_percent="$(echo "$raw_data" | grep "EstimatedChargeRemaining" | cut -d = -f 2)" | |
local bat_percent | |
[[ "${raw_data}" =~ "EstimatedChargeRemaining=([0-9]+)" ]] && bat_percent="${match[1]}" |
# type bat_percent: percent as int in range 0..100 | ||
local bat_percent="$(echo "$raw_data" | grep "EstimatedChargeRemaining" | cut -d = -f 2)" | ||
|
||
local minutes_remaining="$(echo "$raw_data" | grep "EstimatedRunTime" | cut -d = -f 2)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local minutes_remaining="$(echo "$raw_data" | grep "EstimatedRunTime" | cut -d = -f 2)" | |
local minutes_remaining | |
[[ "${raw_data}" =~ "EstimatedRunTime=([0-9]+)" ]] && minutes_remaining="${match[1]}" |
local remain=" ($tstring)" | ||
|
||
local current_state='' | ||
local battery_status="$(echo "$raw_data" | grep "BatteryStatus" | cut -d = -f 2)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local battery_status="$(echo "$raw_data" | grep "BatteryStatus" | cut -d = -f 2)" | |
local battery_status | |
[[ "${raw_data}" =~ "BatteryStatus=([0-9]+)" ]] && battery_status="${match[1]}" |
|
||
local minutes_remaining="$(echo "$raw_data" | grep "EstimatedRunTime" | cut -d = -f 2)" | ||
local tstring="..." | ||
if [[ "$minutes_remaining" =~ "[[:digit:]]+" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check shouldn't be necessary with my previous comment (already greps a digit)..
# https://docs.microsoft.com/ru-ru/windows/desktop/CIMWin32Prov/win32-battery | ||
|
||
# skip empty lines AND empty values, leave only meaningful key=value pairs | ||
local raw_data="$(wmic Path Win32_Battery Get /format:list | tr -d '\r' | sed -n '/=./p')" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filter only meaningful key/value pairs is not necessary IMHO. We are dealing with about 30 keys here. Not very much data.. Also, we would avoid external programs as much as possible (tr
and sed
).
Btw. I just merged another PR that touches the battery segment. Could you update your PR? For the records, here is a sample output of |
Closing in favour of #1120 |
Initial support for battery widget on Windows OS.
It uses WMIC output which looks pretty reliable to parse with stuff like grep and sed.
I admit there's still some work to do, like supporting systems without batteries and respecting
$POWERLEVEL9K_BATTERY_LOW_THRESHOLD
variable.But it's a good starting point, and I would be glad to hear feedback from MINGW / MSYS2 users.