mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-23 23:51:58 +00:00
make battery prompt work on WSL
This commit is contained in:
parent
d80d3a5704
commit
6a1f0659e6
1 changed files with 16 additions and 8 deletions
|
@ -454,20 +454,28 @@ prompt_battery() {
|
||||||
local -i is_full=1 is_calculating is_charching
|
local -i is_full=1 is_calculating is_charching
|
||||||
local dir
|
local dir
|
||||||
for dir in $bats; do
|
for dir in $bats; do
|
||||||
local -i pow=0
|
local -i pow=0 full=0
|
||||||
_p9k_read_file $dir/(energy|charge)_now(N) && (( energy_now+=_P9K_RETVAL ))
|
if _p9k_read_file $dir/(energy_full|charge_full|charge_counter)(N); then
|
||||||
_p9k_read_file $dir/(energy|charge)_full(N) && (( energy_full+=_P9K_RETVAL ))
|
(( energy_full += ${full::=_P9K_RETVAL} ))
|
||||||
_p9k_read_file $dir/(power|current)_now(N) && (( power_now+=${pow::=$_P9K_RETVAL} ))
|
fi
|
||||||
|
if _p9k_read_file $dir/(power|current)_now(N) && (( $#_P9K_RETVAL < 9 )); then
|
||||||
|
(( power_now += ${pow::=$_P9K_RETVAL} ))
|
||||||
|
fi
|
||||||
|
if _p9k_read_file $dir/(energy|charge)_now(N); then
|
||||||
|
(( energy_now += _P9K_RETVAL ))
|
||||||
|
elif _p9k_read_file $dir/capacity(N); then
|
||||||
|
(( energy_now += _P9K_RETVAL * full / 100 ))
|
||||||
|
fi
|
||||||
_p9k_read_file $dir/status(N) && local bat_status=$_P9K_RETVAL || continue
|
_p9k_read_file $dir/status(N) && local bat_status=$_P9K_RETVAL || continue
|
||||||
[[ $bat_status != Full ]] && is_full=0
|
[[ $bat_status != Full ]] && is_full=0
|
||||||
[[ $bat_status == Charging ]] && is_charching=1
|
[[ $bat_status == Charging ]] && is_charching=1
|
||||||
[[ $bat_status == (Charging|Discharging) && $pow == 0 ]] && is_calculating=1
|
[[ $bat_status == (Charging|Discharging) && $pow == 0 ]] && is_calculating=1
|
||||||
done
|
done
|
||||||
|
|
||||||
if (( energy_full )); then
|
(( energy_full )) || return
|
||||||
bat_percent=$(( 100 * energy_now / energy_full ))
|
|
||||||
(( bat_percent > 100 )) && bat_percent=100
|
bat_percent=$(( 100 * energy_now / energy_full ))
|
||||||
fi
|
(( bat_percent > 100 )) && bat_percent=100
|
||||||
|
|
||||||
if (( is_full || bat_percent == 100 )); then
|
if (( is_full || bat_percent == 100 )); then
|
||||||
state=charged
|
state=charged
|
||||||
|
|
Loading…
Reference in a new issue