Tiny Room

终端美化

📅2025/12/30
⏱️2 min
🏷️
终端美化terminaloh-my-posh

核心思想:利用 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 (全平台前提)

nerd字体推荐

  • 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 (推荐,跨平台一致)

  1. 打开配置文件:notepad $PROFILE
  2. 写入以下内容:
# 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 默认)

  1. 编辑 ~/.zshrc
eval "$(oh-my-posh init zsh --config ~/path/to/theme.omp.json)"

分享这篇文章

相关文章