PowerShell + PSReadLine + oh-my-posh & posh-git 实现 oh-my-zsh 效果

本文档介绍了如何在Windows上通过PowerShell、PSReadLine和oh-my-posh来实现类似oh-my-zsh的终端增强效果。首先,你需要下载并安装PowerShell及特定字体,然后通过PowerShellGet模块安装PSReadLine、posh-git和oh-my-posh。接着,配置$Profile文件导入所需模块并设定主题。此外,还需要修改PowerShell的外观设置,选择合适的配色方案和字体。最后,通过设置快捷键和选项,优化PowerShell的交互体验。按照指南操作后,你的PowerShell终端将拥有美观且实用的界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PowerShell + PSReadLine + oh-my-posh & posh-git 实现 oh-my-zsh 效果

最终效果图:

PowerShell 效果图

安装 PowerShell

PowerShell 点击下载最新版 PowerShell。

安装字体

下载并安装 Meslo LG S Regular for Powerline Nerd Font Windows Compatible 字体。

安装 PowerShellGet & PSReadLine

打开 PowerShell 终端,依次输入如下命令:

# 先安装 PowerShellGet
Install-Module -Name PowerShellGet -Force
Exit
# 退出后重新启动 PowerShell 安装 PSReadLine
Install-Module PSReadLine -AllowPrerelease -Force

安装 posh-get & oh-my-posh

Install-Module posh-git -Scope CurrentUser -AllowPrerelease
Install-Module oh-my-posh -Scope CurrentUser -AllowPrerelease

配置文件

code $Profile
# 添加如下内如
if ($host.Name -eq 'ConsoleHost')
{
    Import-Module PSReadLine
}
Import-Module posh-git # 引入 posh-git
Import-Module oh-my-posh # 引入 oh-my-posh

Set-Theme Paradox # 设置主题为 Paradox

Set-PSReadLineOption -PredictionSource History # 设置预测文本来源为历史记录

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 # 设置向下键为前向搜索历史纪录

修改配置文件

Ctrl + , 进入配置页面,点击左侧 PowerShell ,滑动右侧页面至底部,点击外观

Power Shell 配置页面
配置外观,选中配色方案 Tango Dark ,选中字体 Meslo LG S for PowerLine 后,点下方 保存按钮。重启 PowerShell 配置生效。

PowerShell 外观设置页面

最终效果图:

PowerShell 效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hiwb

您的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值