PowerShell 5.1 vs 7
| 维度 | PowerShell 5.1 | PowerShell 7+ |
|---|
| 基础 | .NET Framework | .NET Core/6/7/8/9 |
| 平台 | 仅 Windows | Windows / Linux / macOS |
| 性能 | 较慢 | 快 5~10 倍 |
| 并行 | 基础 | 强 Parallel 支持 |
| 错误处理 | 较啰嗦 | try/catch/finally 现代 |
7+ 改进了并行、错误处理、跨平台兼容性。日常开发建议主力切到 7。
安装 PowerShell 7
1
2
3
4
5
6
7
8
9
10
11
| # 方式一:Winget(推荐)
winget install --id Microsoft.PowerShell
# 方式二:GitHub Release MSI
# https://github.com/PowerShell/PowerShell/releases/download/v7.6.0/PowerShell-7.6.0-win-x64.msi
# 安装目录
C:\Program Files\PowerShell\7
# 验证
pwsh -v
|
Oh My Posh:PowerShell 的 Powerlevel10k
1
2
3
4
5
6
7
8
| # 安装
winget install JanDeDobbeleer.OhMyPosh -s winget
# 更新
winget upgrade JanDeDobbeleer.OhMyPosh -s winget
# 卸载
winget uninstall JanDeDobbeleer.OhMyPosh
|
下载主题
主题仓库:https://github.com/JanDeDobbeleer/oh-my-posh/tree/main/themes
1
2
3
| # 下载一个主题到本地
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/kali.omp.json" `
-OutFile $HOME\kali.omp.json
|
配置 Profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| # 打开配置
notepad $Profile
# 如果文件不存在
New-Item -Path $PROFILE -Type File -Force
# 写入配置
Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineKeyHandler -Key "Ctrl+e" -ScriptBlock {
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptSuggestion()
[Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
}
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete
oh-my-posh init pwsh --config ~\kali.omp.json | Invoke-Expression
# 重新加载
. $PROFILE
# 查当前 shell
oh-my-posh get shell
|
控制台乱码
1
2
| # 控制面板 -> 区域 -> 管理 -> 勾选"使用 Unicode UTF-8 提供全球语言支持"
# 注意:勾选后部分老应用可能乱码,按需切换
|
WezTerm:GPU 加速的跨平台终端
WezTerm 用 Rust + WebGL 写,支持 GPU 合成 + 真彩 + 连字,是 2022 年后 macOS 党、Windows 党、Linux 党三方通吃的选择。
1
2
3
4
5
6
7
| # Debian / Ubuntu
curl -fsSL https://apt.fury.io/wez/gpg.key | sudo gpg --yes --dearmor -o /usr/share/keyrings/wezterm-fury.gpg
echo 'deb [signed-by=/usr/share/keyrings/wezterm-fury.gpg] https://apt.fury.io/wez/ * *' | sudo tee /etc/apt/sources.list.d/wezterm.list
sudo chmod 644 /usr/share/keyrings/wezterm-fury.gpg
sudo apt update
sudo apt install wezterm
|
管理员启动
按住 Ctrl + Shift 同时点击任务栏 WezTerm 图标。
如要每次双击默认管理员启动:
- 找到 WezTerm 快捷方式或
wezterm-gui.exe - 右键 → 属性 → 兼容性
- 勾选"以管理员身份运行此程序"
WezTerm 配置
1
2
| # linux
git clone https://github.com/liangweidonggood/wezterm ~/.config/wezterm
|
键位对照表
| 操作类别 | 小类 | 通用终端/emacs | VIM | wezterm |
|---|
| 光标移动 | 跳到行首 | ctrl + a | 0 / shift + 6 / gg | |
| 跳到行尾 | ctrl + e | shift + 4 / shift + a / shift + g | |
| 上一单词 | ctrl + ← | b | |
| 下一单词 | ctrl + → | w / e | |
| 删除 | 删除光标到行首 | ctrl + u | | |
| 删除光标到行尾 | ctrl + k | dd | |
| 删除光标后字符 | ctrl + d | dw | |
| 常用 | 清屏 | ctrl + l | | |
| 补全 | tab | | |
| 查历史 | ctrl + r | | |
| 模式 | 搜索模式 | | | alt + f |
| 标签 | 新标签 | | | alt + t |
| 左右分屏 | | | ctrl + alt + \ |
| 上下分屏 | | | alt + \ |
| 切换标签 | | | alt + [ ] |
| 移动标签 | | | ctrl + alt + [ ] |
emacs 键位
| 按键 | 动作 |
|---|
| ctrl + a | 移动到行首 |
| ctrl + e | 移动到行尾 |
| ctrl + b | 光标向后移动一个字符 |
| ctrl + f | 光标向前移动一个字符 |
| alt + b | 光标向后移动一个单词 |
| alt + f | 光标向前移动一个单词 |
| ctrl + d | 删除光标所在位置的字符 |
| ctrl + k | 删除从光标到行尾的内容 |
| ctrl + u | 删除从光标到行首的内容 |
| ctrl + w | 删除前一个单词 |
| alt + d | 删除后一个单词 |
| ctrl + t | 交换光标前后的字符 |
psmux:tmux 的 Windows 版
1
2
| scoop bucket add psmux https://github.com/psmux/scoop-psmux
scoop install psmux
|
环境变量
PowerShell 区分 User(用户级)和 Machine(系统级,需管理员):
1
2
3
4
5
6
7
8
9
10
11
12
| # 追加 Path
[Environment]::SetEnvironmentVariable("Path",
[Environment]::GetEnvironmentVariable("Path", "User") + ";D:\portable\single\bin",
"User")
# 添加
[Environment]::SetEnvironmentVariable("CLAUDE_CODE_GIT_BASH_PATH",
"<DEV_DIR>\Git\bin\bash.exe",
[EnvironmentVariableTarget]::User)
# 删除
[Environment]::SetEnvironmentVariable("MyVar", $null, "User")
|
字体:Nerd Font
1
2
3
4
| # 下载 JetBrains Mono
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/JetBrainsMono.zip
# 解压 -> 全选 -> 右键 -> 为所有用户安装
|
下一步
- 想要 IDE 集成(VSCode / IDEA 终端用上这些),看 2018-01-15《Windows 开发工具链》
- 想要 AI 编程体验(Claude Code / OpenCode / Cursor),看 2019-04-15《AI 编程工具链》
参考资料
- PowerShell 官方:https://github.com/PowerShell/PowerShell
- Oh My Posh:https://ohmyposh.dev/
- WezTerm:https://wezterm.org
- psmux:https://github.com/psmux/scoop-psmux