Windows 终端美化配置教程
本教程将指导你配置一个美观、高效的 Windows 终端环境,适用于 Claude Code 等开发工具。
目录
环境说明
| 组件 | 说明 |
|---|---|
| Windows Terminal | 终端窗口(容器),支持多标签、分屏、美化 |
| PowerShell 7 | Shell 解释器,实际执行命令的程序 |
| Maple Mono 字体 | 支持中文的等宽编程字体,包含 Nerd Font 图标 |
| Oh My Posh | 终端提示符美化工具 |
为什么用 PowerShell 7 而不是 CMD?
Shift+Tab切换 Plan Mode 正常工作(需 Node v24.2.0/v22.17.0+)Alt+V粘贴剪贴板图片- 支持 Linux 风格命令别名(ls、cat、rm)
- MCP Server 配置更方便
1. 安装 Windows Terminal
Windows 10/11 通常已预装。如果没有:
方法一:Microsoft Store
- 打开 Microsoft Store
- 搜索 “Windows Terminal”
- 点击安装
方法二:WinGet 命令
winget install Microsoft.WindowsTerminal
打开方式:
- 按
Win键,输入terminal或终端 - 或按
Win + R,输入wt回车 - 或在任意文件夹右键 → 「在终端中打开」
2. 安装 PowerShell 7
打开 Windows Terminal(或 CMD/PowerShell),运行:
winget install Microsoft.PowerShell --accept-source-agreements --accept-package-agreements
等待安装完成,会显示「已成功安装」。
验证安装:
pwsh --version
应显示类似 PowerShell 7.5.4 的版本号。
3. 配置默认终端
安装完 PowerShell 7 后,需要将其设置为 Windows Terminal 的默认 Shell,并配置管理员权限。
步骤一:设置默认配置文件
- 完全关闭 Windows Terminal(包括所有标签页)
- 重新打开 Windows Terminal
- 点击顶部下拉箭头
∨→ 选择「设置」 - 在左侧找到「启动」页面
- 找到「默认配置文件」下拉框
- 选择 PowerShell(黑底图标,不是蓝底的 Windows PowerShell)
- 点击右下角「保存」
步骤二:设置默认以管理员身份运行(重要!)
- 在设置页面左侧,找到「配置文件」→「PowerShell」(黑底图标那个)
- 点击进入 PowerShell 配置
- 找到「以管理员身份运行此配置文件」选项
- 开启 此选项
- 点击「保存」
这样每次打开 Windows Terminal 时,PowerShell 7 都会以管理员权限运行,避免权限不足的问题。
区分方法:
| 名称 | 图标 | 版本 |
|---|---|---|
| Windows PowerShell | 蓝底 | 5.1(系统自带) |
| PowerShell | 黑底 | 7.x(刚安装的) |
注意: 「默认终端应用程序」保持「让 Windows 决定」即可,只需要改「默认配置文件」和管理员权限设置。
4. 安装 Maple Mono 字体
Maple Mono 是一款支持中文的等宽编程字体,包含 Nerd Font 图标,非常适合终端使用。
下载字体
访问 GitHub 下载页面:
https://github.com/subframe7536/maple-font/releases
下载 MapleMonoNormal-NF-CN.zip(推荐,包含中文 + Nerd Font 图标)
安装字体
- 解压下载的 zip 文件
- 进入解压后的文件夹
- 选中所有
.ttf文件(按Ctrl+A) - 右键 → 选择「为所有用户安装」(重要!不是普通的「安装」)
- 等待安装完成
配置终端字体
- 打开 Windows Terminal 设置
- 左侧选择「配置文件」→「PowerShell」
- 点击「其他设置」→「外观」
- 在「字体」下拉框中选择
Maple Mono NF CN或Maple Mono Normal NF CN - 保存设置
注意: 如果字体列表中找不到,请:
- 确认使用「为所有用户安装」方式安装
- 完全关闭并重新打开 Windows Terminal
5. 安装 Oh My Posh
Oh My Posh 是一个终端提示符美化工具,可以显示 Git 分支、目录图标等信息。
使用一键配置脚本(推荐)
本教程提供了一键配置脚本,可以自动完成 Oh My Posh 的安装和配置。
使用步骤:
- 打开 Windows Terminal(确保使用 PowerShell 7,黑底图标)
- 进入脚本所在目录,运行:
& "xx:\xx\setup-ohmyposh.ps1"
- 等待脚本执行完成
- 关闭所有终端窗口,重新打开
注意: 不要右键点击脚本选择「使用 PowerShell 运行」,因为那样会使用 Windows PowerShell 5.1 而不是 PowerShell 7,可能导致闪退。
手动安装(备选方案)
如果脚本无法运行,可以手动安装:
步骤 1:安装 Oh My Posh
winget install JanDeDobbeleer.OhMyPosh --source winget --scope user --force --accept-source-agreements --accept-package-agreements
步骤 2:创建 Profile 文件
# 如果文件不存在,创建它
if (!(Test-Path $PROFILE)) { New-Item -Path $PROFILE -Type File -Force }
步骤 3:编辑 Profile 文件
notepad $PROFILE
步骤 4:添加以下内容,保存文件
# Oh My Posh 初始化
oh-my-posh init pwsh | Invoke-Expression
步骤 5:关闭所有终端窗口,重新打开
更换主题(可选)
Oh My Posh 有很多主题可选,访问:Themes | Oh My Posh
选好主题后,修改 Profile 文件:
# 使用指定主题
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\主题名.omp.json" | Invoke-Expression
常用主题推荐:
agnoster- 经典主题powerlevel10k_rainbow- 彩虹风格paradox- 简洁现代
6. 验证配置
重新打开 Windows Terminal,检查以下内容:
检查 PowerShell 版本
$PSVersionTable.PSVersion
应显示 7.x.x
检查 Oh My Posh
终端提示符应该变得更好看,显示当前目录、Git 分支等信息。
检查字体
终端中的图标应该正常显示,不会出现方块或乱码。
常见问题
Q: 字体安装后在终端设置中找不到?
A: 确保使用「为所有用户安装」方式,然后完全关闭并重新打开 Windows Terminal。
Q: Oh My Posh 图标显示为方块?
A: 需要安装 Nerd Font 字体(如 Maple Mono NF CN),并在终端设置中选择该字体。
Q: PowerShell 7 没有出现在终端配置文件列表中?
A: 完全关闭 Windows Terminal,重新打开后应该会自动识别。
Q: Profile 文件在哪里?
A: 运行 echo $PROFILE 查看路径,通常是:
C:\Users\用户名\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
完整配置清单
| 组件 | 安装命令 |
|---|---|
| Windows Terminal | winget install Microsoft.WindowsTerminal |
| PowerShell 7 | winget install Microsoft.PowerShell |
| Oh My Posh | winget install JanDeDobbeleer.OhMyPosh |
| Maple Mono 字体 | 从 GitHub 下载安装 |
参考链接
# Oh My Posh 一键配置脚本
# 右键 -> 使用 PowerShell 运行
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Oh My Posh 一键配置脚本" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "当前 PowerShell 版本: $($PSVersionTable.PSVersion)" -ForegroundColor Gray
# 警告:如果不是 PowerShell 7,给出提示但继续执行
if ($PSVersionTable.PSVersion.Major -lt 7) {
Write-Host ""
Write-Host "[警告] 当前使用的是 Windows PowerShell $($PSVersionTable.PSVersion)" -ForegroundColor Yellow
Write-Host " 脚本将为 PowerShell 7 配置 Profile" -ForegroundColor Yellow
Write-Host " 请确保已安装 PowerShell 7" -ForegroundColor Yellow
}
Write-Host ""
# 步骤 1: 安装 Oh My Posh
Write-Host "[1/3] 正在安装 Oh My Posh..." -ForegroundColor Yellow
try {
$result = winget install JanDeDobbeleer.OhMyPosh --source winget --scope user --force --accept-source-agreements --accept-package-agreements 2>&1
Write-Host $result
Write-Host "[OK] Oh My Posh 安装完成" -ForegroundColor Green
} catch {
Write-Host "[!] Oh My Posh 可能已安装,继续配置..." -ForegroundColor Yellow
}
Write-Host ""
# 步骤 2: 创建 PowerShell 7 的 Profile(使用固定路径,不依赖当前 PowerShell 版本)
Write-Host "[2/3] 正在配置 PowerShell 7 Profile..." -ForegroundColor Yellow
# PowerShell 7 的 Profile 路径(固定路径,不使用 $PROFILE 变量)
$ps7ProfileDir = Join-Path $env:USERPROFILE "Documents\PowerShell"
$ps7ProfilePath = Join-Path $ps7ProfileDir "Microsoft.PowerShell_profile.ps1"
Write-Host " Profile 路径: $ps7ProfilePath" -ForegroundColor Gray
# 创建目录
if (!(Test-Path $ps7ProfileDir)) {
New-Item -ItemType Directory -Path $ps7ProfileDir -Force | Out-Null
Write-Host " - 已创建目录" -ForegroundColor Gray
}
# Oh My Posh 配置内容
$ohmyposhConfig = "oh-my-posh init pwsh | Invoke-Expression"
# 创建或更新 Profile 文件
if (Test-Path $ps7ProfilePath) {
$content = Get-Content $ps7ProfilePath -Raw -ErrorAction SilentlyContinue
if ($content -and $content -match "oh-my-posh") {
Write-Host " - Profile 中已存在 Oh My Posh 配置" -ForegroundColor Gray
} else {
Add-Content -Path $ps7ProfilePath -Value "`n# Oh My Posh 初始化`n$ohmyposhConfig"
Write-Host " - 已添加 Oh My Posh 配置" -ForegroundColor Gray
}
} else {
$profileContent = @"
# PowerShell 7 Profile
# 由 setup-ohmyposh.ps1 脚本自动生成
# Oh My Posh 初始化
$ohmyposhConfig
"@
Set-Content -Path $ps7ProfilePath -Value $profileContent -Encoding UTF8
Write-Host " - 已创建 Profile 文件" -ForegroundColor Gray
}
Write-Host "[OK] Profile 配置完成" -ForegroundColor Green
Write-Host ""
# 步骤 3: 显示结果
Write-Host "[3/3] 配置完成!" -ForegroundColor Yellow
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " 配置摘要" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Profile 文件: $ps7ProfilePath" -ForegroundColor White
Write-Host ""
Write-Host "Profile 内容:" -ForegroundColor White
Write-Host "----------------------------------------" -ForegroundColor DarkGray
if (Test-Path $ps7ProfilePath) {
Get-Content $ps7ProfilePath | ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
}
Write-Host "----------------------------------------" -ForegroundColor DarkGray
Write-Host ""
Write-Host "[重要] 下一步操作:" -ForegroundColor Yellow
Write-Host " 1. 关闭所有 Windows Terminal 窗口" -ForegroundColor White
Write-Host " 2. 重新打开 Windows Terminal" -ForegroundColor White
Write-Host " 3. 确保使用的是 PowerShell 7 (黑底图标)" -ForegroundColor White
Write-Host ""
Write-Host "如果图标显示为方块,请在终端设置中选择 Nerd Font 字体" -ForegroundColor Yellow
Write-Host "(如 Maple Mono NF CN)" -ForegroundColor Yellow
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " 完成!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "按任意键退出..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")