powershell@命令行提示符样式配置自定义@pwsh重写prompt显示电量内存时间等信息
# 自定义PowerShell提示符以显示时间、日期、当前目录和电池信息
function prompt {
$time = Get-Date -Format 'HH:mm:ss'
$date = Get-Date -Format 'yyyy-MM-dd'
$path = Get-Location
$battery = Get-WmiObject -Class Win32_Battery -Namespace "root\wmi" | Select-Object -Property EstimatedChargeRemaining
$batteryPercent = $battery.EstimatedChargeRemaining
Write-Host -NoNewline -ForegroundColor Green "$date "
Write-Host -NoNewline -ForegroundColor Yellow $time
Write-Host -NoNewline -ForegroundColor Cyan " $path"
Write-Host -NoNewline -ForegroundColor Magenta " [Battery: $batteryPercent%]"
"`n$ "
}
这段代码定义了一个名为prompt
的函数,用于自定义PowerShell提示符样式。它会显示当前日期、时间、当前目录和电池剩余电量百分比。这对于需要频繁查看这些信息的用户来说非常便捷。
评论已关闭