Windows Terminal 简单美化
  NRAmgwynyURQ 2023年12月01日 227 0

需要用到的软件/插件

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

安装 oh-my-posh

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

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

Windows Terminal 简单美化_PowerShell

安装字体

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

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

Windows Terminal 简单美化_git_02

安装 posh-git

PowerShellGet\Install-Module posh-git -Scope CurrentUser # -Scope CurrentUser 表示当前用户

安装/升级 PSReadLine

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

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

Windows Terminal 简单美化_PowerShell_03

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

配置文件

notepad $profile # 有 vscode 可以使用 code $prifile 来配置

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

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

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

参考/附录



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月01日 0

暂无评论

推荐阅读
NRAmgwynyURQ