system-management 核心脚本存档(PowerShell / Nu / Bash) 📅 2026/7/18 13:38:14 1. 核心.bat 关联双击执行右键 Zed 编辑文件scripts/powershell/set-bat-assoc.ps1# 硬编码修改此处路径 $zedPath C:\Users\user\AppData\Local\Programs\Zed\Zed.exe 恢复双击执行关键不改默认打开方式 Set-ItemProperty -Path HKCU:\Software\Classes.bat -Name (default) -Value batfile -Force 添加右键菜单项 $editPath HKCU:\Software\Classes\batfile\shell\EditWithZed New-Item -Path $editPath -Force | Out-Null Set-ItemProperty -Path $editPath -Name (default) -Value 用 Zed 编辑 -Force 绑定命令 $commandPath $editPath\command New-Item -Path $commandPath -Force | Out-Null Set-ItemProperty -Path $commandPath -Name (default) -Value $zedPath %1 -Force 清理系统缓存必须否则不生效 Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.bat\UserChoice -Recurse -Force -ErrorAction SilentlyContinue 刷新 Explorer Stop-Process -Name explorer -Force; Start-Sleep 2; Start-Process explorer.exe2. 兜底强制默认应用.bat .txt文件scripts/powershell/set-zed-defaults-full.ps1$zedPath C:\Users\user\AppData\Local\Programs\Zed\Zed.exe function Set-FileAssociation { param($ext, $progId) # 写注册表 Set-ItemProperty -Path HKCU:\Software\Classes.$ext -Name (default) -Value $progId -Force Set-ItemProperty -Path HKCU:\Software\Classes$progId\shell\open\command -Name (default) -Value $zedPath %1 -Force # 干掉 UserChoice 劫持 Remove-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.$ext\UserChoice -Recurse -Force -ErrorAction SilentlyContinue } Set-FileAssociation -ext txt -progId Zed.txt Set-FileAssociation -ext bat -progId Zed.bat 刷新 Stop-Process -Name explorer -Force; Start-Sleep 2; Start-Process explorer.exe3. 清理右键菜单垃圾项文件scripts/powershell/clean-bat-menu.ps1$shellPath HKCU:\Software\Classes\batfile\shell Get-ChildItem $shellPath | ForEach-Object { # 只保留系统默认的 open, edit, runas if ($_.PSChildName -notin open,edit,runas) { Remove-Item $_.PSPath -Recurse -Force } }4. 验证PowerShell 环境文件scripts/powershell/verify-shells.ps1# 检查核心命令是否存在 pwsh,nu,bash,git,ssh | ForEach-Object { $cmd Get-Command $_ -ErrorAction SilentlyContinue if ($cmd) { Write-Host ✓ $_ : $($cmd.Source) } else { Write-Host ✗ $_ : Not Found } }5. 验证Nushell 环境文件scripts/nushell/verify-shells.nu# 检查命令 let cmds [pwsh, nu, bash, git, ssh] $cmds | each { |cmd| if (which $cmd | is-empty) { print $✗ ($cmd): Not Found } else { print $✓ ($cmd): Found } }6. 跨 Shell 调用Bash 封装文件scripts/powershell/test-bash-command.ps1# 测试从 PWSH 调用 Bash bash -c echo PWSH - Bash OK # 测试从 PWSH 调用 Nu nu -c version7. 系统优化禁用粘滞键文件scripts/powershell/disable-sticky-keys.ps1# 506 禁用快捷键 Set-ItemProperty -Path HKCU:\Control Panel\Accessibility\StickyKeys -Name Flags -Value 5068. 代理环境Scoop 安装逻辑关键逻辑片段用于安装 Nu# 必须同时设置 ENV 和 .NET 代理 $proxy New-Object System.Net.WebProxy(http://127.0.0.1:7897) [System.Net.WebRequest]::DefaultWebProxy $proxy $env:HTTP_PROXY http://127.0.0.1:7897 $env:HTTPS_PROXY http://127.0.0.1:7897 iwr https://get.scoop.sh | iex9. Nushell 配置Bash 别名文件config.nu# 允许调用外部 Git Bash alias bash ^C:/Program Files/Git/bin/bash.exe # 关闭启动 Banner $env.config.show_banner false硬编码清单Agent 必读C:\Users\user\→ 替换为%USERPROFILE%Zed.exe 路径 → 替换为实际编辑器路径127.0.0.1:7897→ 替换为实际代理端口