Windows PowerShell 7 Linux 化配置指南
长期使用 Linux 和 macOS 后,Windows 默认 PowerShell 的体验会比较割裂。
目标不是把 PowerShell 改造成 bash,而是保留 PowerShell 对象管道优势,同时引入现代 CLI 工具,形成统一开发环境。
最终效果:
- macOS:zsh + starship + eza + fzf + nvim
- Ubuntu:bash/zsh + starship + eza + fzf + nvim
- Windows:PowerShell 7 + starship + eza + fzf + nvim
1. 安装 PowerShell 7
查看版本:
$PSVersionTable.PSVersion
安装:
winget install Microsoft.PowerShell
启动:
pwsh
2. 安装现代 CLI 工具
winget install sharkdp.bat
winget install BurntSushi.ripgrep.MSVC
winget install eza-community.eza
winget install junegunn.fzf
winget install ajeetdsouza.zoxide
winget install Starship.Starship
winget install Neovim.Neovim
对应关系:
Linux Windows 功能
cat bat 文件查看 ls eza 文件列表 grep rg 搜索 cd zoxide 智能目录跳转 vim nvim 编辑器
3. 配置 PowerShell Profile
查看:
$PROFILE
创建目录:
New-Item -ItemType Directory -Path (Split-Path $PROFILE) -Force
创建文件:
New-Item $PROFILE -ItemType File -Force
编辑:
nvim $PROFILE
加入:
Invoke-Expression (& { (zoxide init powershell | Out-String) })
Invoke-Expression (&starship init powershell)
Set-PSReadLineOption -EditMode Vi
4. zoxide 替代 cd
传统:
cd C:\Users\kevin\projects\comfyui
使用 zoxide 后:
z comfyui
查看历史:
zoxide query -l
交互选择:
zi
5. eza 替代 ls
PowerShell 默认 ls 是 Get-ChildItem。
在 profile 中加入:
function ls {
eza --icons
}
function ll {
eza -lah --icons
}
以后:
ll
效果类似:
ls -lah
6. bat 替代 cat
bat filename
优势:
- 语法高亮
- 行号显示
- 更适合代码阅读
7. ripgrep 替代 grep
搜索:
rg "keyword"
特点:
- Rust 编写
- 快速
- 默认适配代码仓库
8. fzf 模糊搜索
运行:
fzf
进行文件搜索。
结合 zoxide:
zi
可以快速跳转常用目录。
9. Starship 美化终端
安装:
winget install Starship.Starship
配置:
Invoke-Expression (&starship init powershell)
可以显示:
- Git 分支
- Python 环境
- Node 版本
- Docker 状态
10. Neovim 统一编辑环境
安装:
winget install Neovim.Neovim
配置目录:
~/.config/nvim/
这样 Mac、Linux、Windows 可以共享同一套配置。
11. SSH 管理服务器
配置:
C:\Users\kevin\.ssh\config
示例:
Host ai-server
HostName 192.168.1.xxx
User kevin
IdentityFile ~/.ssh/aikey
以后:
ssh ai-server
即可登录 Ubuntu AI Server。
最终环境
PowerShell 7
|
+-- Starship
+-- zoxide
+-- eza
+-- bat
+-- ripgrep
+-- fzf
+-- Neovim
配置完成后,Windows 可以拥有接近 Linux/macOS 的开发体验,并且三套系统保持一致的工作流。