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

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

参考/附录

相关推荐
阿白的白日梦3 天前
winget基础管理---更新/修改源为国内源
windows
埃博拉酱7 天前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
唐宋元明清21888 天前
.NET 本地Db数据库-技术方案选型
windows·c#
加号38 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
tryCbest8 天前
Windows环境下配置pip镜像源
windows·pip
呉師傅8 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
百事牛科技8 天前
保护文档安全:PDF限制功能详解与实操
windows·pdf
一个人旅程~8 天前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑
一个假的前端男8 天前
[特殊字符] Flutter 安装完整指南 Windows—— 2026最新版
windows·flutter
倚肆8 天前
在 Windows Docker 中安装并配置 Nginx (映射 Windows 端口与路径)
windows·nginx·docker