Skip to content

Commit 55fa882

Browse files
committed
docs: make powershell profile setup idempotent
Close #595
1 parent e77ccc4 commit 55fa882

4 files changed

Lines changed: 40 additions & 7 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ echo 'eval "$(vfox activate zsh)"' >> ~/.zshrc
4747
echo 'vfox activate fish | source' >> ~/.config/fish/config.fish
4848

4949
# For PowerShell:
50-
if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force }
51-
echo 'Invoke-Expression "$(vfox activate pwsh)"' >> $PROFILE
50+
if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force | Out-Null }
51+
$vfoxLine = 'Invoke-Expression "$(vfox activate pwsh)"'
52+
$profileContent = Get-Content -Path $PROFILE -Raw
53+
if ($profileContent -notmatch [regex]::Escape($vfoxLine)) {
54+
if ($profileContent.Length -gt 0 -and -not $profileContent.EndsWith("`r`n") -and -not $profileContent.EndsWith("`n")) {
55+
Add-Content -Path $PROFILE -Value ""
56+
}
57+
Add-Content -Path $PROFILE -Value $vfoxLine
58+
}
5259
5360
# For Clink:
5461
# 1. Install clink: https://github.com/chrisant996/clink/releases

README_CN.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ echo 'eval "$(vfox activate zsh)"' >> ~/.zshrc
4343
echo 'vfox activate fish | source' >> ~/.config/fish/config.fish
4444

4545
# 对于 PowerShell
46-
if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force }; Add-Content -Path $PROFILE -Value 'Invoke-Expression "$(vfox activate pwsh)"'
46+
if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force | Out-Null }
47+
$vfoxLine = 'Invoke-Expression "$(vfox activate pwsh)"'
48+
$profileContent = Get-Content -Path $PROFILE -Raw
49+
if ($profileContent -notmatch [regex]::Escape($vfoxLine)) {
50+
if ($profileContent.Length -gt 0 -and -not $profileContent.EndsWith("`r`n") -and -not $profileContent.EndsWith("`n")) {
51+
Add-Content -Path $PROFILE -Value ""
52+
}
53+
Add-Content -Path $PROFILE -Value $vfoxLine
54+
}
4755
4856
# 对于 Clink:
4957
# 1. 安装 clink: https://github.com/chrisant996/clink/releases
@@ -124,4 +132,3 @@ $ node -v
124132
125133
[Apache 2.0 license](./LICENSE) - Copyright (C) 2026 Han Li
126134
and [contributors](https://github.com/version-fox/vfox/graphs/contributors)
127-

docs/guides/quick-start.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,19 @@ echo 'vfox activate fish | source' >> ~/.config/fish/config.fish
116116
Create PowerShell configuration:
117117

118118
```powershell
119-
if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force }; Add-Content -Path $PROFILE -Value 'Invoke-Expression "$(vfox activate pwsh)"'
119+
if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force | Out-Null }
120+
$vfoxLine = 'Invoke-Expression "$(vfox activate pwsh)"'
121+
$profileContent = Get-Content -Path $PROFILE -Raw
122+
if ($profileContent -notmatch [regex]::Escape($vfoxLine)) {
123+
if ($profileContent.Length -gt 0 -and -not $profileContent.EndsWith("`r`n") -and -not $profileContent.EndsWith("`n")) {
124+
Add-Content -Path $PROFILE -Value ""
125+
}
126+
Add-Content -Path $PROFILE -Value $vfoxLine
127+
}
120128
```
121129

130+
This snippet is safe to run multiple times. It avoids duplicating the vfox activation line and ensures it is written on a new line.
131+
122132
If PowerShell prompts "cannot be loaded because the execution of scripts is disabled on this system", **run PowerShell as Administrator** and execute:
123133

124134
```powershell
@@ -344,4 +354,3 @@ Congratulations on completing the `vfox` quick start! Now you can:
344354
**Next Steps**:
345355
346356
Use `vfox --help` to see more commands and options, or visit [All Commands](../usage/all-commands.md) to learn more features.
347-

docs/zh-hans/guides/quick-start.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,19 @@ echo 'vfox activate fish | source' >> ~/.config/fish/config.fish
116116
创建 PowerShell 配置:
117117

118118
```powershell
119-
if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force }; Add-Content -Path $PROFILE -Value 'Invoke-Expression "$(vfox activate pwsh)"'
119+
if (-not (Test-Path -Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force | Out-Null }
120+
$vfoxLine = 'Invoke-Expression "$(vfox activate pwsh)"'
121+
$profileContent = Get-Content -Path $PROFILE -Raw
122+
if ($profileContent -notmatch [regex]::Escape($vfoxLine)) {
123+
if ($profileContent.Length -gt 0 -and -not $profileContent.EndsWith("`r`n") -and -not $profileContent.EndsWith("`n")) {
124+
Add-Content -Path $PROFILE -Value ""
125+
}
126+
Add-Content -Path $PROFILE -Value $vfoxLine
127+
}
120128
```
121129

130+
这段脚本可以重复执行。它会避免重复写入 vfox 激活行,并确保该行写入到新的一行中。
131+
122132
如果 PowerShell 提示「在此系统上禁止运行脚本」,请**以管理员身份运行 PowerShell** 并执行:
123133

124134
```powershell

0 commit comments

Comments
 (0)