Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

Commit 41828ae

Browse files
rashil2000JanDeDobbeleer
authored andcommitted
Remove further unnecessary function calls
1 parent d417d59 commit 41828ae

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Helpers/Prompt.ps1

+10-7
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,26 @@ function Set-Newline {
228228
function Get-BatteryInfo {
229229
if ($env:OS -eq 'Windows_NT' -or $IsWindows) {
230230

231-
if (!(Get-CimInstance win32_battery)) { return }
231+
$batteryclass = Get-CimInstance win32_battery
232+
if (!$batteryclass) { return }
232233

233-
$charge = (Get-CimInstance win32_battery).EstimatedChargeRemaining
234-
$connected = (Get-CimInstance -Class batterystatus -Namespace root\wmi).PowerOnline
235-
$charging = (Get-CimInstance -Class batterystatus -Namespace root\wmi).Charging
234+
$powerclass = Get-CimInstance -Class batterystatus -Namespace root\wmi
235+
$charge = $batteryclass.EstimatedChargeRemaining
236+
$connected = $powerclass.PowerOnline
237+
$charging = $powerclass.Charging
236238

237239
} elseif ($IsLinux) {
238240

239241
$syspath = "/sys/class/power_supply/"
240-
if (!(Get-ChildItem $syspath)) { return }
242+
$syspathcontents = Get-ChildItem $syspath
243+
if (!$syspathcontents) { return }
241244

242-
$powerclass = (Get-ChildItem $syspath | Where-Object { $_.Name -like 'AC*' }).Name
245+
$powerclass = ($syspathcontents | Where-Object { $_.Name -like 'AC*' }).Name
243246
if ($powerclass -is [Object[]]) { $powerdevice = $syspath + $powerclass[-1] }
244247
else { $powerdevice = $syspath + $powerclass }
245248
$connected = Get-Content "$powerdevice/online"
246249

247-
$batteryclass = (Get-ChildItem $syspath | Where-Object { $_.Name -like 'BAT*' }).Name
250+
$batteryclass = ($syspathcontents | Where-Object { $_.Name -like 'BAT*' }).Name
248251
if ($batteryclass -is [Object[]]) { $batterydevice = $syspath + $batteryclass[-1] }
249252
else { $batterydevice = $syspath + $batteryclass }
250253
$charge = Get-Content "$batterydevice/capacity"

0 commit comments

Comments
 (0)