1配置 PowerShell 代理环境
先在主页面打开 PowerShell 下载页并完成安装,然后在 Windows Terminal 中打开 PowerShell 标签页,逐条执行以下命令:
❯
if (!(Test-Path -Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }
❯
notepad $PROFILE
在记事本中粘贴配置内容,然后 Ctrl+S 保存并关闭
配置.txt
PowerShell $PROFILE 配置内容
if (Test-Path Alias:curl) { Remove-Item Alias:curl }
if (Test-Path Alias:wget) { Remove-Item Alias:wget }
$PH = "http://127.0.0.1:10808"
$PS5 = "socks5://127.0.0.1:10808"
function proxy {
$env:all_proxy = $env:ALL_PROXY = $env:http_proxy = $env:HTTP_PROXY = `
$env:https_proxy = $env:HTTPS_PROXY = $PH
if (Get-Command git -EA 0) { git config --global http.proxy $PS5; git config --global https.proxy $PS5 }
if (Get-Command npm -EA 0) { npm config set proxy $PH 2>$null; npm config set https-proxy $PH 2>$null }
if (Get-Command yarn -EA 0) { yarn config set proxy $PH 2>$null; yarn config set https-proxy $PH 2>$null }
Write-Host "Proxy ON" -ForegroundColor Green
}
function unproxy {
'all_proxy','ALL_PROXY','http_proxy','https_proxy','HTTP_PROXY','HTTPS_PROXY' | `
ForEach-Object { Remove-Item "Env:\$_" -EA 0 }
if (Get-Command git -EA 0) { git config --global --unset http.proxy 2>$null; git config --global --unset https.proxy 2>$null }
if (Get-Command npm -EA 0) { npm config delete proxy 2>$null; npm config delete https-proxy 2>$null }
if (Get-Command yarn -EA 0) { yarn config delete proxy 2>$null; yarn config delete https-proxy 2>$null }
Write-Host "Proxy OFF" -ForegroundColor Yellow
}
proxy
❯
. $PROFILE
重新加载后终端显示 "Proxy ON" 即配置成功。之后可用 proxy / unproxy 随时开关。