File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,8 +47,15 @@ echo 'eval "$(vfox activate zsh)"' >> ~/.zshrc
4747echo ' 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
Original file line number Diff line number Diff line change @@ -43,7 +43,15 @@ echo 'eval "$(vfox activate zsh)"' >> ~/.zshrc
4343echo ' 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
126134and [contributors](https://github.com/version-fox/vfox/graphs/contributors)
127-
Original file line number Diff line number Diff line change @@ -116,9 +116,19 @@ echo 'vfox activate fish | source' >> ~/.config/fish/config.fish
116116Create 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+
122132If 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
346356Use `vfox --help` to see more commands and options, or visit [All Commands](../usage/all-commands.md) to learn more features.
347-
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments