使用vscode打开配置文件
1code $PROFILE
编写Prompt函数
该函数返回值即为powersehll显示效果。
1function Prompt {
2 $dir = $PWD.Path
3 $branch = ""
4 if (Test-Path "${dir}/.git/HEAD") {
5 $head = Get-Content "${dir}/.git/HEAD"
6 $branch = $head -replace 'ref: refs/heads/', ''
7 $branch = " git:($branch)"
8 }
9
10 $currentTime = Get-Date -Format " HH:mm:ss"
11
12 # 获取当前路径的最后一级文件夹
13 $currentDir = Split-Path (Get-Location) -Leaf
14 if ($dir -eq $env:userprofile) {
15 $currentDir = "~"
16 }
17
18
19 $batteryInfo = Get-CimInstance -ClassName Win32_Battery
20 $battery = ""
21 if ($batteryInfo.BatteryStatus -eq 2) {
22 $battery = " ⚡" + $batteryInfo.EstimatedChargeRemaining + "%"
23 } else {
24 $battery = " 🔋" + $batteryInfo.EstimatedChargeRemaining + "%"
25 }
26
27 $promptString = "➜ " + $currentDir
28
29 "`e[1;32m" + $promptString +"`e[1;33m" + $battery + "`e[1;36m" + $currentTime + "`e[1;34m" + $branch + "`e[m "
30}