Windows Terminal 简单美化

需要用到的软件/插件

  • oh-my-posh
  • posh-git
  • PSReadLine

安装 oh-my-posh

oh-my-posh 是 shell 主题引擎,使用 winget 来安装 oh-my-posh

bash 复制代码
winget serach oh-my-posh # 找到对应的 id 方便在下一步使用(具体见下图)
winget install JanDeDobbeleer.OhMyPosh # 等该命令执行完成就安装好了

安装字体

由于 oh-my-posh 主题一般都有一些比较特殊的符号,如果安装后 powershell 提示符出现方框类的字符就需要安装字体了。

bash 复制代码
oh-my-posh font install # 如果安装 oh-my-posh 时是全局安装则需要管理员权限去执行这条命令

安装 posh-git

bash 复制代码
PowerShellGet\Install-Module posh-git -Scope CurrentUser # -Scope CurrentUser 表示当前用户

安装/升级 PSReadLine

bash 复制代码
PowerShellGet\Install-Module posh-git -Scope CurrentUser 
# -Scope CurrentUser 表示当前用户
# Install-Module 安装模块
# Update-Module 升级模块

安装之后的效果(灰色部分为之前输入过的命令,可以按方向键的上下进行切换):

这个工具主要做命令提示管理等操作;安装操作可选的( 这个模块是自带的,如果不可用时需要卸载并重新安装)

配置文件

bash 复制代码
notepad $profile # 有 vscode 可以使用 code $prifile 来配置

在弹出的窗口中将下面的内容复制进入即可

bash 复制代码
Import-Module posh-git  # 在当前打开的 PowerShell 终端中引入 posh-git(已安装,这里只是引入)
Import-Module PSReadLine  # 这个工具主要做命令提示管理等操作,默认集成在 PowerShell 中,不需要安装
Set-PSReadlineKeyHandler -Key Tab -Function Complete  # 设置 Tab 键补全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete  # 设置 Ctrl+D 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo  # 设置 Ctrl+Z 为撤销
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward  # 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward  # 设置向下键为前向搜索历史记录

# 启动时加载 ohMyPosh
# --config 是加载 oh-my-posh 配置的
oh-my-posh init pwsh --config D:\Software\oh-my-posh\conf\pure.omp.json | Invoke-Expression
Import-Module scoop-completion

最后重启终端就可以看到效果了。

参考/附录

相关推荐
Mintopia2 分钟前
一个月速成 AI 工程师:从代码小白到智能工匠的修炼手册
前端·javascript·aigc
Mintopia5 分钟前
Next.js 全栈:接收和处理请求
前端·javascript·next.js
袁煦丞39 分钟前
2025.8.18实验室【代码跑酷指南】Jupyter Notebook程序员的魔法本:cpolar内网穿透实验室第622个成功挑战
前端·程序员·远程工作
Joker Zxc43 分钟前
【前端基础】flex布局中使用`justify-content`后,最后一行的布局问题
前端·css
无奈何杨1 小时前
风控系统事件分析中心,关联关系、排行、时间分布
前端·后端
Moment1 小时前
nginx 如何配置防止慢速攻击 🤔🤔🤔
前端·后端·nginx
晓得迷路了1 小时前
栗子前端技术周刊第 94 期 - React Native 0.81、jQuery 4.0.0 RC1、Bun v1.2.20...
前端·javascript·react.js
前端小巷子1 小时前
Vue 自定义指令
前端·vue.js·面试
玲小珑1 小时前
Next.js 教程系列(二十七)React Server Components (RSC) 与未来趋势
前端·next.js