refactor: 极速精简终端配置指南#17
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
This PR refactors and significantly trims the Windows Terminal setup post to focus on a “restore-lab” (还原机房) scenario: installing PowerShell 7 + using Windows Terminal (Unpackaged) + forcing UTF-8 to eliminate GBK mojibake.
Changes:
- Streamlined the guide and scripts by removing Oh My Posh, Nerd Font installation/registration, and MSIX-based Terminal installation.
- Kept a minimal one-click script flow: install PS7, unzip Terminal, write PS7 profile for UTF-8, write Terminal settings, create a desktop shortcut.
- Simplified FAQ and moved the multi-proxy download fallback script to an appendix.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| Write-Host ">>> 下载 Windows Terminal (Unpackaged 备用)..." -ForegroundColor Cyan | ||
| Invoke-WebRequest -Uri "https://github.com/microsoft/terminal/releases/download/v1.21.3231.0/Microsoft.WindowsTerminal_1.21.3231.0_x64.zip" -OutFile $wtZip -UseBasicParsing | ||
| # --- 2. 下载并解压 Windows Terminal(Unpackaged,无需管理员)--- |
| @@ -51,96 +39,30 @@ if ((Get-FileHash $ps7Out -Algorithm SHA256).Hash -ne $ps7Hash) { | |||
| Write-Host ">>> 安装 PowerShell 7.4..." -ForegroundColor Cyan | |||
| msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 | |||
| @@ -51,96 +39,30 @@ if ((Get-FileHash $ps7Out -Algorithm SHA256).Hash -ne $ps7Hash) { | |||
| Write-Host ">>> 安装 PowerShell 7.4..." -ForegroundColor Cyan | |||
| msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 | |||
caf7ca3 to
d0078da
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
content/posts/win-terminal-setup.md:258
- 代理版脚本同样把
$LASTEXITCODE -ne 0直接当成失败;MSI 的 3010/1641 往往代表“安装成功但需要重启”。建议与上方直连版保持一致:接受 0、3010、1641 并给出重启提示,否则在正常安装后会误报失败。
Write-Host ">>> 安装 PowerShell 7.4..." -ForegroundColor Cyan
msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1 REGISTER_MANIFEST=1
if ($LASTEXITCODE -ne 0) {
throw "PowerShell 7.4 安装失败,退出码: $LASTEXITCODE"
}
| msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1 REGISTER_MANIFEST=1 | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "PowerShell 7.4 安装失败,退出码: $LASTEXITCODE" | ||
| } |
| | **系统** | Windows 10 / 11(64 位) | | ||
| | **权限** | 管理员(还原卡环境,重启还原) | | ||
| | **场景** | 机房、OS-Easy 还原卡 | | ||
| | **目标** | PowerShell 7 + Windows Terminal + 强制 UTF-8 | |
| | `/qn` | 静默安装,无弹窗 | | ||
| | `ADD_EXPLORER_CONTEXT_MENU=1` | 在资源管理器右键菜单添加"在此处打开 PowerShell 7" | | ||
| | `REGISTER_MANIFEST=1` | 注册事件日志清单 | | ||
| | `ADD_EXPLORER_CONTEXT_MENU=1` | 右键菜单添加"在此处打开 PowerShell 7" | |
- 砍掉字体下载/解压/注册整节(系统自带 Consolas + Segoe UI Emoji 已够用) - 砍掉 Oh My Posh 美化(还原机房功能优先,外观其次) - 砍掉 msixbundle 双保险(只保留 Unpackaged 版,最稳妥) - 合并分步详解为 3 节,FAQ 砍到 3 个 - 代理版脚本同步精简并后移至附录 - 685行/28.6KB → 353行/13.2KB,下载节点从5个减到2个 - 本地 PS5.1 + conhost 实测:Profile 加载后 UTF-8 生效,中文/Emoji 正常
d0078da to
ba831c2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
content/posts/win-terminal-setup.md:115
- 生成的
settings.json也是用Set-Content直接覆盖写入,会无条件抹掉用户现有的 Windows Terminal 配置(配色/快捷键/自定义 profiles 等)。建议写入前先备份原文件,或仅修改必要字段(如 defaultProfile / actions)并保留其余配置。
}
'@
Set-Content -Path "$wtSettingsDir\settings.json" -Value $settingsJson -Encoding UTF8
| # --- 3. 写 PowerShell 7 Profile(强制 UTF-8)--- | ||
| $ps7ProfileDir = "$env:USERPROFILE\Documents\PowerShell" | ||
| New-Item -ItemType Directory -Force -Path $ps7ProfileDir | Out-Null | ||
| $profileContent = @" | ||
| # 强制 UTF-8,根治 GBK 乱码 | ||
| [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | ||
| `$OutputEncoding = [System.Text.Encoding]::UTF8 | ||
| `$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8' | ||
|
|
||
| # Oh My Posh 主题 | ||
| & "$ompExe" init pwsh --config "$themeFile" | Invoke-Expression | ||
|
|
||
| # 常用别名 | ||
| Set-Alias ll Get-ChildItem | ||
| Set-Alias which Get-Command | ||
|
|
||
| # 历史预测 | ||
| Set-PSReadLineOption -PredictionSource History | ||
| Set-PSReadLineOption -PredictionViewStyle ListView | ||
| "@ | ||
| Set-Content -Path "$ps7ProfileDir\Microsoft.PowerShell_profile.ps1" -Value $profileContent -Encoding UTF8 |
| # --- 1. 下载并安装 PowerShell 7.4 --- | ||
| $ps7Url = "https://github.com/PowerShell/PowerShell/releases/download/v7.4.6/PowerShell-7.4.6-win-x64.msi" | ||
| $ps7Out = "$temp\PowerShell-7.4.6-win-x64.msi" | ||
| if (Test-Path $ps7Out) { | ||
| Write-Host ">>> 检测到旧的 PowerShell 7.4 安装包,删除后重新下载..." -ForegroundColor Yellow | ||
| Remove-Item $ps7Out -Force | ||
| } | ||
| if (Test-Path $ps7Out) { Remove-Item $ps7Out -Force } |
| } | ||
| if (Test-Path $ps7Out) { Remove-Item $ps7Out -Force } | ||
| Write-Host ">>> 下载 PowerShell 7.4..." -ForegroundColor Cyan | ||
| Invoke-WebRequest -Uri $ps7Url -OutFile $ps7Out -UseBasicParsing |
| # 自动 fallback 下载函数 | ||
| function Get-WithProxy { | ||
| param([string]$Url, [string]$OutFile) | ||
| # 强制关闭进度条,避免代理环境下小数据块导致频繁 UI 刷新拖慢下载 | ||
| $ProgressPreference = 'SilentlyContinue' | ||
| $proxies = @( |
- 提取 PS7/WT 版本号为变量,避免升级时漏改 - Invoke-WebRequest 增加 -ErrorAction Stop 与 -TimeoutSec 300 - Profile 与 settings.json 写入前自动备份原文件 - Get-WithProxy 用 try/finally 恢复 $ProgressPreference
|
已针对 Copilot review comments 提交修复(commit _2b4ccda_):
请 Copilot 重新 review,如有其他问题继续修。 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (3)
content/posts/win-terminal-setup.md:205
- FAQ 这里直接运行的命令同样写死了
terminal-1.21.3231.0,与脚本当前使用的$wtVer/terminal-$wtVer不一致。建议同步更新为当前版本目录,或改成提示用户按实际解压目录名替换版本号。
直接运行:
```powershell
& "$env:LOCALAPPDATA\WindowsTerminal\terminal-1.21.3231.0\WindowsTerminal.exe"
**content/posts/win-terminal-setup.md:253**
* 代理版脚本里 `Invoke-WebRequest` 同样使用了 `-UseBasicParsing`,在 PowerShell 7 下会报参数不存在并导致所有代理/直连尝试都失败。建议与主脚本一致做版本判断:仅在 Windows PowerShell 5.1 传 `-UseBasicParsing`,在 PS7 省略。
$proxyUrl = "$p$Url"
Write-Host "Trying $proxyUrl ..." -ForegroundColor DarkGray
try {
Invoke-WebRequest -Uri $proxyUrl -OutFile $OutFile -UseBasicParsing -TimeoutSec 120 -ErrorAction Stop
if ((Get-Item $OutFile).Length -gt 1024) {
**content/posts/win-terminal-setup.md:273**
* 代理版脚本中也写了“版本号(升级时只需改这里)”,但后面的 `$ps7Hash` / `$wtZipHash` 仍与具体版本绑定。建议同样修正文案或把 hash 按版本组织,避免读者只改版本号导致校验失败。
版本号(升级时只需改这里)
$ps7Ver = "7.4.6"
$wtVer = "1.21.3231.0"
</details>
| } | ||
| return $false | ||
| } | ||
| # 版本号(升级时只需改这里) |
| | **Windows Terminal 设置** | `%LOCALAPPDATA%\Microsoft\Windows Terminal\settings.json` | | ||
| | **PowerShell 7 Profile** | `%USERPROFILE%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1` | | ||
| | **Oh My Posh 本体** | `%LOCALAPPDATA%\Programs\oh-my-posh\oh-my-posh.exe` | | ||
| | **字体文件** | `%LOCALAPPDATA%\Microsoft\Windows\Fonts\` | | ||
| | **Unpackaged Terminal** | `%LOCALAPPDATA%\WindowsTerminal\terminal-1.21.3231.0\WindowsTerminal.exe` | | ||
|
|
| if (Test-Path $ps7Out) { Remove-Item $ps7Out -Force } | ||
| Write-Host ">>> 下载 PowerShell 7.4..." -ForegroundColor Cyan | ||
| Invoke-WebRequest -Uri $ps7Url -OutFile $ps7Out -UseBasicParsing | ||
| Invoke-WebRequest -Uri $ps7Url -OutFile $ps7Out -UseBasicParsing -ErrorAction Stop -TimeoutSec 300 |
- 版本号注释改为'版本号与 SHA256(升级时需同步更新)',避免误导 - 配置速查表与 FAQ 路径统一为变量形式,与脚本保持一致
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
content/posts/win-terminal-setup.md:377
- 代理版脚本同样用
$env:USERPROFILE\Desktop写入快捷方式,遇到桌面重定向/OneDrive/域策略会失败。建议改用[Environment]::GetFolderPath('Desktop')来生成快捷方式路径。
$wtExe = "$wtDest\terminal-$wtVer\WindowsTerminal.exe"
$WshShell = New-Object -ComObject WScript.Shell
$SC = $WshShell.CreateShortcut("$env:USERPROFILE\Desktop\Terminal.lnk")
$SC.TargetPath = $wtExe
$SC.WorkingDirectory = "$wtDest\terminal-$wtVer"
$SC.IconLocation = $wtExe
$SC.Save()
content/posts/win-terminal-setup.md:285
- 代理版脚本同样已用
$ps7Ver参数化版本号,但提示文案仍写死为“PowerShell 7.4…”,升级版本时容易遗漏导致文案与实际版本不一致。建议提示文案也改为使用$ps7Ver。
# --- 1. 下载并安装 PowerShell 7.4 ---
$ps7Url = "https://github.com/PowerShell/PowerShell/releases/download/v$ps7Ver/PowerShell-$ps7Ver-win-x64.msi"
$ps7Out = "$temp\PowerShell-$ps7Ver-win-x64.msi"
if (Test-Path $ps7Out) { Remove-Item $ps7Out -Force }
Write-Host ">>> 下载 PowerShell 7.4..." -ForegroundColor Cyan
Get-WithProxy -Url $ps7Url -OutFile $ps7Out
$ps7Hash = "ed331a04679b83d4c013705282d1f3f8d8300485eb04c081f36e11eaf1148bd0"
if ((Get-FileHash $ps7Out -Algorithm SHA256).Hash -ne $ps7Hash) {
throw "PowerShell 7.4 安装包 SHA256 校验失败"
}
Write-Host ">>> 安装 PowerShell 7.4..." -ForegroundColor Cyan
msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1
| 直接运行: | ||
| ```powershell | ||
| & "$env:LOCALAPPDATA\WindowsTerminal\terminal-1.21.3231.0\WindowsTerminal.exe" | ||
| & "$env:LOCALAPPDATA\WindowsTerminal\terminal-$wtVer\WindowsTerminal.exe" | ||
| ``` |
| $wtExe = "$wtDest\terminal-$wtVer\WindowsTerminal.exe" | ||
| $WshShell = New-Object -ComObject WScript.Shell | ||
| $SC = $WshShell.CreateShortcut("$env:USERPROFILE\Desktop\Terminal.lnk") | ||
| $SC.TargetPath = $wtExe | ||
| $SC.WorkingDirectory = "$wtDest\terminal-1.21.3231.0" | ||
| $SC.WorkingDirectory = "$wtDest\terminal-$wtVer" | ||
| $SC.IconLocation = $wtExe | ||
| $SC.Save() |
| # --- 1. 下载并安装 PowerShell 7.4 --- | ||
| $ps7Url = "https://github.com/PowerShell/PowerShell/releases/download/v7.4.6/PowerShell-7.4.6-win-x64.msi" | ||
| $ps7Out = "$temp\PowerShell-7.4.6-win-x64.msi" | ||
| if (Test-Path $ps7Out) { | ||
| Write-Host ">>> 检测到旧的 PowerShell 7.4 安装包,删除后重新下载..." -ForegroundColor Yellow | ||
| Remove-Item $ps7Out -Force | ||
| } | ||
| $ps7Url = "https://github.com/PowerShell/PowerShell/releases/download/v$ps7Ver/PowerShell-$ps7Ver-win-x64.msi" | ||
| $ps7Out = "$temp\PowerShell-$ps7Ver-win-x64.msi" | ||
| if (Test-Path $ps7Out) { Remove-Item $ps7Out -Force } | ||
| Write-Host ">>> 下载 PowerShell 7.4..." -ForegroundColor Cyan | ||
| Invoke-WebRequest -Uri $ps7Url -OutFile $ps7Out -UseBasicParsing | ||
| Invoke-WebRequest -Uri $ps7Url -OutFile $ps7Out -UseBasicParsing -ErrorAction Stop -TimeoutSec 300 | ||
| $ps7Hash = "ed331a04679b83d4c013705282d1f3f8d8300485eb04c081f36e11eaf1148bd0" | ||
| if ((Get-FileHash $ps7Out -Algorithm SHA256).Hash -ne $ps7Hash) { | ||
| throw "PowerShell 7.4 安装包 SHA256 校验失败" | ||
| } | ||
| Write-Host ">>> 安装 PowerShell 7.4..." -ForegroundColor Cyan | ||
| msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 | ||
|
|
||
| # --- 2. 下载并安装 Windows Terminal --- | ||
| $wtMsix = "$temp\WindowsTerminal.msixbundle" | ||
| $wtZip = "$temp\WindowsTerminal_x64.zip" | ||
| if (Test-Path $wtMsix) { | ||
| Write-Host ">>> 检测到旧的 Windows Terminal 安装包,删除后重新下载..." -ForegroundColor Yellow | ||
| Remove-Item $wtMsix -Force | ||
| msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1 |
- 桌面快捷方式改用 [Environment]::GetFolderPath('Desktop'),兼容重定向/OneDrive/域策略
- Write-Host 提示文案改为 变量,避免升级时文案与实际版本不一致
- FAQ 单行命令改回写死版本号,防止读者单独复制时变量未定义
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (3)
content/posts/win-terminal-setup.md:49
- 安装失败时的异常信息仍写死为 “PowerShell 7.4 安装失败”,但实际安装的版本由
$ps7Ver决定。建议用$ps7Ver生成错误信息,避免版本升级后报错信息误导。
Write-Host ">>> 安装 PowerShell $ps7Ver..." -ForegroundColor Cyan
msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1
if ($LASTEXITCODE -notin @(0, 3010, 1641)) {
throw "PowerShell 7.4 安装失败,退出码: $LASTEXITCODE"
}
content/posts/win-terminal-setup.md:283
- 代理版脚本在 SHA256 校验失败时仍硬编码为 “PowerShell 7.4 安装包 SHA256 校验失败”,但实际版本由
$ps7Ver决定。建议错误信息使用$ps7Ver,避免版本升级后校验失败提示不准确。
$ps7Hash = "ed331a04679b83d4c013705282d1f3f8d8300485eb04c081f36e11eaf1148bd0"
if ((Get-FileHash $ps7Out -Algorithm SHA256).Hash -ne $ps7Hash) {
throw "PowerShell 7.4 安装包 SHA256 校验失败"
}
content/posts/win-terminal-setup.md:288
- 代理版脚本安装失败的异常信息仍写死为 “PowerShell 7.4 安装失败”,与
$ps7Ver可能不一致。建议将异常信息中的版本号改为$ps7Ver,并与前面的下载/安装提示保持一致,便于排障。
Write-Host ">>> 安装 PowerShell $ps7Ver..." -ForegroundColor Cyan
msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1
if ($LASTEXITCODE -notin @(0, 3010, 1641)) {
throw "PowerShell 7.4 安装失败,退出码: $LASTEXITCODE"
}
| Write-Host ">>> 下载 PowerShell 7.4..." -ForegroundColor Cyan | ||
| Invoke-WebRequest -Uri $ps7Url -OutFile $ps7Out -UseBasicParsing | ||
| Invoke-WebRequest -Uri $ps7Url -OutFile $ps7Out -UseBasicParsing -ErrorAction Stop -TimeoutSec 300 | ||
| $ps7Hash = "ed331a04679b83d4c013705282d1f3f8d8300485eb04c081f36e11eaf1148bd0" | ||
| if ((Get-FileHash $ps7Out -Algorithm SHA256).Hash -ne $ps7Hash) { | ||
| throw "PowerShell 7.4 安装包 SHA256 校验失败" |
| 直接运行: | ||
| ```powershell | ||
| & "$env:LOCALAPPDATA\WindowsTerminal\terminal-1.21.3231.0\WindowsTerminal.exe" |
- throw/Write-Host 中硬编码的 PowerShell 7.4 全部改为 $ps7Ver 变量 - FAQ 启动命令改为 terminal-<版本> 占位符,与配置速查表一致,并提示替换
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
content/posts/win-terminal-setup.md:291
- 代理版脚本同样未显式禁用自动重启;如果 msiexec 返回 1641 并触发重启,会直接中断后续 Terminal 解压/配置写入。建议同主脚本一样给 msiexec 增加
/norestart(或REBOOT=ReallySuppress),并按返回码分别提示。
Write-Host ">>> 安装 PowerShell $ps7Ver..." -ForegroundColor Cyan
msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1
if ($LASTEXITCODE -notin @(0, 3010, 1641)) {
throw "PowerShell $ps7Ver 安装失败,退出码: $LASTEXITCODE"
}
if ($LASTEXITCODE -in @(3010, 1641)) {
Write-Host ">>> 安装成功,但需要重启才能完全生效。" -ForegroundColor Yellow
}
content/posts/win-terminal-setup.md:376
- 代理版同样在创建桌面快捷方式前未校验
$wtExe是否存在;一旦解压目录名与预期不一致会产生无效快捷方式且仍提示完成。建议在保存快捷方式前检查Test-Path $wtExe,失败时提示用户查看$wtDest下的实际目录结构。
# --- 5. 桌面快捷方式 ---
$wtExe = "$wtDest\terminal-$wtVer\WindowsTerminal.exe"
$WshShell = New-Object -ComObject WScript.Shell
$SC = $WshShell.CreateShortcut("$([Environment]::GetFolderPath('Desktop'))\Terminal.lnk")
$SC.TargetPath = $wtExe
$SC.WorkingDirectory = "$wtDest\terminal-$wtVer"
$SC.IconLocation = $wtExe
| Write-Host ">>> 安装 PowerShell $ps7Ver..." -ForegroundColor Cyan | ||
| msiexec /i "$ps7Out" /qn ADD_EXPLORER_CONTEXT_MENU=1 | ||
| if ($LASTEXITCODE -notin @(0, 3010, 1641)) { | ||
| throw "PowerShell $ps7Ver 安装失败,退出码: $LASTEXITCODE" | ||
| } |
| # --- 5. 创建桌面快捷方式 --- | ||
| $wtExe = "$wtDest\terminal-$wtVer\WindowsTerminal.exe" | ||
| $WshShell = New-Object -ComObject WScript.Shell | ||
| $SC = $WshShell.CreateShortcut("$env:USERPROFILE\Desktop\Terminal.lnk") | ||
| $SC = $WshShell.CreateShortcut("$([Environment]::GetFolderPath('Desktop'))\Terminal.lnk") | ||
| $SC.TargetPath = $wtExe | ||
| $SC.WorkingDirectory = "$wtDest\terminal-1.21.3231.0" | ||
| $SC.WorkingDirectory = "$wtDest\terminal-$wtVer" |
|
|
||
| ```powershell | ||
| msiexec /i "PowerShell-7.4.6-win-x64.msi" /qn ADD_EXPLORER_CONTEXT_MENU=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 | ||
| msiexec /i "PowerShell-7.4.6-win-x64.msi" /qn ADD_EXPLORER_CONTEXT_MENU=1 |
- msiexec 增加 REBOOT=ReallySuppress,防止还原卡环境被自动重启清空配置 - 退出码仅接受 0/3010,1641 视为失败 - 创建桌面快捷方式前 Test-Path 校验 wtExe,不存在则抛错 - 分步详解示例命令改为 PowerShell-<版本>-win-x64.msi 占位符
| # --- 5. 桌面快捷方式 --- | ||
| $wtExe = "$wtDest\terminal-$wtVer\WindowsTerminal.exe" | ||
| $WshShell = New-Object -ComObject WScript.Shell | ||
| $SC = $WshShell.CreateShortcut("$env:USERPROFILE\Desktop\Terminal.lnk") | ||
| $SC = $WshShell.CreateShortcut("$([Environment]::GetFolderPath('Desktop'))\Terminal.lnk") | ||
| $SC.TargetPath = $wtExe | ||
| $SC.WorkingDirectory = "$wtDest\terminal-1.21.3231.0" | ||
| $SC.WorkingDirectory = "$wtDest\terminal-$wtVer" |
| # 自动 fallback 下载函数 | ||
| function Get-WithProxy { | ||
| param([string]$Url, [string]$OutFile) | ||
| # 强制关闭进度条,避免代理环境下小数据块导致频繁 UI 刷新拖慢下载 | ||
| $oldProgress = $ProgressPreference | ||
| $ProgressPreference = 'SilentlyContinue' |
- 直连版与代理版脚本开头均增加管理员权限检测,非管理员直接 throw - 代理版创建快捷方式前增加 Test-Path 校验 wtExe,与直连版一致
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (3)
content/posts/win-terminal-setup.md:65
- 同上:这里的
Invoke-WebRequest ... -UseBasicParsing会在 PowerShell 7+ 直接失败。建议同样做兼容处理(条件参数/移除-UseBasicParsing)。
$wtUrl = "https://github.com/microsoft/terminal/releases/download/v$wtVer/Microsoft.WindowsTerminal_$($wtVer)_x64.zip"
if (Test-Path $wtZip) { Remove-Item $wtZip -Force }
Write-Host ">>> 下载 Windows Terminal $wtVer..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $wtUrl -OutFile $wtZip -UseBasicParsing -ErrorAction Stop -TimeoutSec 300
$wtZipHash = "8FB268B93C9B99D6CF553709C2C58BF1B2FF4B364199152E09221DFB2A44BBF5"
content/posts/win-terminal-setup.md:262
- 代理版脚本里
Invoke-WebRequest仍使用-UseBasicParsing,在 PowerShell 7+ 会报参数不存在并中断 fallback。建议与主脚本一致做兼容处理(条件性添加该参数或移除)。
$proxyUrl = "$p$Url"
Write-Host "Trying $proxyUrl ..." -ForegroundColor DarkGray
try {
Invoke-WebRequest -Uri $proxyUrl -OutFile $OutFile -UseBasicParsing -TimeoutSec 120 -ErrorAction Stop
if ((Get-Item $OutFile).Length -gt 1024) {
Write-Host "Success via $p" -ForegroundColor Green
content/posts/win-terminal-setup.md:270
- 同上:直连分支的
Invoke-WebRequest ... -UseBasicParsing在 PowerShell 7+ 不兼容。建议同样做条件参数/移除处理,避免代理全部失败后最后一步反而因参数问题失败。
}
Write-Host "Trying direct download..." -ForegroundColor Yellow
Invoke-WebRequest -Uri $Url -OutFile $OutFile -UseBasicParsing -ErrorAction Stop -TimeoutSec 300
} finally {
$ProgressPreference = $oldProgress
| > ⚠️ **必须以管理员身份运行 PowerShell**(右键 → 以管理员身份运行),否则 PS7 MSI 安装会失败。 | ||
|
|
||
| 在 PowerShell 里复制粘贴执行(支持 PowerShell 5.1 老窗口): | ||
|
|
||
| ```powershell | ||
| # 检测管理员权限 | ||
| if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | ||
| throw "请以管理员身份运行 PowerShell(右键 → 以管理员身份运行),否则 MSI 安装会失败。" |
| $ps7Out = "$temp\PowerShell-$ps7Ver-win-x64.msi" | ||
| if (Test-Path $ps7Out) { Remove-Item $ps7Out -Force } | ||
| Write-Host ">>> 下载 PowerShell $ps7Ver..." -ForegroundColor Cyan | ||
| Invoke-WebRequest -Uri $ps7Url -OutFile $ps7Out -UseBasicParsing -ErrorAction Stop -TimeoutSec 300 |
- Replace direct msiexec call with Start-Process -Wait -PassThru to reliably capture ExitCode in PS5.1 (fixes false-negative failure) - Change 3010 hint from 'needs reboot' to 'no reboot needed, usable now' plus restore-card warning (prevents user from rebooting and losing all) Applies to both direct-download and proxy-fallback script blocks. Refs: Copilot review comments #3238355175, #3238478891
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
content/posts/win-terminal-setup.md:307
- 代理版脚本同样在
$exitCode -eq 3010时输出“无需重启”。3010 通常表示“成功但需要重启”,建议与直连版保持一致,明确提示“需要重启但已禁止自动重启(REBOOT=ReallySuppress)”,避免读者误判安装状态。
if ($exitCode -eq 3010) {
Write-Host ">>> PS7 已安装成功,无需重启,当前即可使用。" -ForegroundColor Green
Write-Host ">>> ⚠️ 还原卡环境:重启后需重新运行本脚本。" -ForegroundColor Yellow
| Write-Host ">>> PS7 已安装成功,无需重启,当前即可使用。" -ForegroundColor Green | ||
| Write-Host ">>> ⚠️ 还原卡环境:重启后需重新运行本脚本。" -ForegroundColor Yellow |
- 0: '无需重启,当前即可使用' - 3010: 如实告知'安装程序提示需要重启',同时说明已禁止自动重启 Refs: #17 (comment)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
content/posts/win-terminal-setup.md:169
- 分步详解里的手动安装命令与一键脚本不一致:脚本通过
REBOOT=ReallySuppress禁止自动重启并处理 3010 退出码,但这里的msiexec示例未包含该参数。建议在示例命令中也补上REBOOT=ReallySuppress(并在旁边说明 3010 的含义),否则读者按步骤手动执行时可能触发自动重启/还原导致配置丢失。
```powershell
msiexec /i "PowerShell-<版本>-win-x64.msi" /qn ADD_EXPLORER_CONTEXT_MENU=1
**content/posts/win-terminal-setup.md:165**
* 文章正文标题“安装 PowerShell 7.4”是硬编码版本号,但脚本已用 `$ps7Ver` 变量控制版本。建议把该小节标题改为不绑定具体小版本(例如“安装 PowerShell 7($ps7Ver)”或“安装 PowerShell 7.x”),避免后续升级时文案过期。
分步详解
1. 安装 PowerShell 7.4
Windows 自带的 PowerShell 5.1 默认编码是 GBK,Unicode 支持差、很多新语法不支持。
</details>
| $ps7Ver = "7.4.6" | ||
| $wtVer = "1.21.3231.0" | ||
|
|
||
| # --- 1. 下载并安装 PowerShell 7.4 --- |
| # PR #17 处理进度:refactor: 极速精简终端配置指南 | ||
|
|
||
| ## 基本信息 | ||
|
|
||
| - **PR**: https://github.com/yang12535/blog/pull/17 | ||
| - **分支**: `refactor/slim-terminal-guide` | ||
| - **文件**: `content/posts/win-terminal-setup.md` | ||
| - **目标**: 还原机房 PowerShell 7 + Windows Terminal 极速配置(conhost + PS5.1) | ||
|
|
||
| --- | ||
|
|
||
| ## 迭代记录 | ||
|
|
||
| ### Round 1 — 已有修复(前序 commit) | ||
|
|
||
| | # | 问题 | 状态 | | ||
| |---|---|---| | ||
| | 3238355152 | "Unpackaged,无需管理员" 表述误导 | ✅ 已移除 | | ||
| | 3238355175 | msiexec /qn 失败不报错 | ✅ `$LASTEXITCODE` 检查(0/3010/1641) | | ||
| | 3238355185 | ENABLE_PSREMOTING=1 额外暴露面 | ✅ 已移除 | | ||
| | 3238432347 | 代理版 `$LASTEXITCODE -ne 0` 误判 | ✅ 同步修复 | | ||
| | 3238432358 | 缺少管理员运行提示 | ✅ 增加 ⚠️ 提示 | | ||
| | 3238432372 | REGISTER_MANIFEST=1 参数表缺失 | ✅ 从示例中移除 | | ||
|
|
||
| ### Round 2 — commit `2b4ccda` | ||
|
|
||
| | # | 问题 | 修复方式 | | ||
| |---|---|---| | ||
| | 3238478870 | Profile/settings.json 直接覆盖 | 写入前自动备份到 `.backup.时间戳` | | ||
| | 3238478891 | 多处硬编码版本号 | 提取 `$ps7Ver` / `$wtVer` 变量 | | ||
| | 3238478908 | Invoke-WebRequest 无超时/错误处理 | 统一加 `-ErrorAction Stop -TimeoutSec 300` | | ||
| | 3238478930 | `$ProgressPreference` 副作用外泄 | `Get-WithProxy` 用 `try/finally` 恢复旧值 | | ||
|
|
||
| ### Round 3 — commit `f93bfbf` | ||
|
|
||
| | # | 问题 | 修复方式 | | ||
| |---|---|---| | ||
| | 3240714045 | "升级时只需改这里" 文案误导 | 改为"版本号与 SHA256(升级时需同步更新)" | | ||
| | 3240714077 | 文档路径硬编码版本号 | 配置速查表与 FAQ 改为变量/占位符形式 | | ||
| | 3240714101 | `-UseBasicParsing` 在 PS7 不支持 | **未修改** — 脚本明确在 PS5.1 运行,该参数在 PS5.1 是**必需**的 | | ||
|
|
||
| ### Round 4 — commit `7bd3989` | ||
|
|
||
| | # | 问题 | 修复方式 | | ||
| |---|---|---| |
PR17_PROGRESS.md is internal tracking, not site content.
变更摘要
对
win-terminal-setup.md进行极速精简,聚焦还原机房核心需求:PowerShell 7 + Windows Terminal + UTF-8 不乱码。砍掉的内容
保留的核心
数据对比
本地实测
在还原机房环境(Windows 10 19043 + PS5.1 + conhost)测试通过:
[Console]::OutputEncoding从gb2312→utf-8