核心思想:利用
Oh My Posh作为全平台通用的提示符引擎,配合Nerd Fonts解决图标渲染,通过Git/Cloud同步配置文件,实现“一次配置,到处运行”。
🏗️ 基础架构 (The Stack)
| 组件 | 作用 | 推荐方案 |
|---|---|---|
| Terminal Emulator | 渲染容器 | Windows Terminal / iTerm2 / WezTerm |
| Shell | 脚本解释器 | PowerShell (跨平台) / Zsh / Fish |
| Prompt Engine | 提示符美化 | Oh My Posh (全平台一致性最高) |
| Icons | 文件列表图标 | Terminal-Icons (pwsh) / lsd / exa |
| Font | 图标显示基础 | Nerd Fonts (必装) |
📥 第一步:安装核心组件
1. 安装 Nerd Fonts (全平台前提)
- Windows:
oh-my-posh font install(管理员运行)。 - macOS/Linux: 使用 Homebrew 或手动下载
.ttf放入~/.local/share/fonts。
2. 安装 Oh My Posh
- Windows:
winget install JanDeDobbeleer.OhMyPosh -s winget - macOS:
brew install jandedobbeleer/oh-my-posh/oh-my-posh - Linux:
curl -s https://ohmyposh.dev/install.sh | bash -s
⚙️ 第二步:配置文件设置 (The Profile)
根据你使用的 Shell,将启动命令写入对应的配置文件中。
若使用 PowerShell (推荐,跨平台一致)
- 打开配置文件:
notepad $PROFILE - 写入以下内容:
# 1. 启动 Oh My Posh (指向你的主题文件)
oh-my-posh init pwsh --config "~/Documents/PowerShell/my_theme.omp.json" | Invoke-Expression
# 2. 启动 Terminal Icons (需要先 Install-Module Terminal-Icons)
Import-Module -Name Terminal-Icons
# 3. 自定义别名 (Alias)
Set-Alias -Name g -Value git
Set-Alias -Name cls -Value Clear-Host若使用 Zsh (macOS/Linux 默认)
- 编辑
~/.zshrc:
eval "$(oh-my-posh init zsh --config ~/path/to/theme.omp.json)"