PowerShell 安装 oh-my-posh.v3

卸载 oh-my-posh

https://ohmyposh.dev/docs/migrating

Uninstall-Module oh-my-posh -AllVersions

Windows 安装

官方教程:https://ohmyposh.dev/docs/installation/windows
补充(重要):https://lamirs.vercel.app/powershell%E7%BE%8E%E5%8C%96/

Step1 安装模块

以管理员身份运行 powershell,执行以下命令,

Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))

# 如果以下命令无法成功执行,重新打开 powershell,再次运行即可
Install-Module posh-git -Scope CurrentUser  ## posh-git git美化管理包
Install-Module oh-my-posh -Scope CurrentUser  ## oh-my-posh 基础美化工具包

Step2 修改配置文件

https://ohmyposh.dev/docs/migrating

code/notepad $PROFILE

添加以下内容,

Import-Module posh-git
oh-my-posh init pwsh | Invoke-Expression
oh-my-posh init pwsh --config
  • 第一条命令表示导入 posh-git
  • 第二条命令表示导入 oh-my-posh

分别使用以下命令使得配置生效:

# git init
conda init powershell  # 注意:这里必须加上 powershell

主题配置(这里以 robbyrussel 为例)

官方主题:https://ohmyposh.dev/docs/themes#robbyrussel

Step1 修改 powershell 配置文件 C:\Users\xxx\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

Import-Module posh-git
oh-my-posh init pwsh | Invoke-Expression
# oh-my-posh init pwsh --config ~/Documents/PowerShell/themes/robbyrussel.omp.json | Invoke-Expression

Step2 到官网下载主题的配置文件

image.png

点击这个链接就会进入到 github 官网,对应主题的 json 文件,直接下载到本地,或者在本地创建一个 json 文件,把里面内容复制进去即可。


image.png

修改 robbyrussel 主题的配置文件,因为默认的配置文件使用 conda init 之后还是无法显示当前使用的虚拟环境,

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "python",
          "style": "plain",
          "foreground": "#E5E4E2",
          "properties": {
            "prefix": "(",
            "postfix":") ",
            "display_virtual_env": true,
            "display_default": true,
            "display_version": false,
            "display_mode": "always"
          }
        },
        {
          "type": "text",
          "style": "plain",
          "foreground": "#98C379",
          "properties": {
            "prefix": "",
            "text": "\u279C",
            "postfix": ""
          }
        },
        {
          "type": "path",
          "style": "plain",
          "foreground": "#56B6C2",
          "properties": {
            "style": "folder"
          }
        },
        {
          "type": "git",
          "style": "plain",
          "foreground": "#D0666F",
          "properties": {
            "branch_icon": "",
            "display_status": false,
            "prefix": "<#5FAAE8>git:(</>",
            "postfix": "<#5FAAE8>)</>"
          }
        },
        {
          "type": "exit",
          "style": "plain",
          "foreground": "#DCB977",
          "properties": {
            "prefix": "\u2717",
            "display_exit_code": false
          }
        }
      ]
    }
  ],
  "final_space": true
}

字体图标显示不全解决办法

image.png

下载完成后,右键选择为所有的用户安装:


image.png
image.png

安装完毕之后,可以在系统中看到已经安装好的 Meslo 字体:

image.png

将字体更改为以上 Meslo 中的一种即可,这里使用官方推荐的字体 MesloLGM NF (图中第二行、第三列)。

image.png

image.png

禁用 powershell 启动输出提示:


image.png
pwsh -nolog

最终效果:


image.png

最后,如果显卡驱动没有安装好,也是会造成字体显示不全的,这里附上 Inte 官方显卡驱动下载安装链接:https://www.intel.cn/content/www/cn/zh/support/intel-driver-support-assistant.html,具体安装好没有,可以到设备管理器里面进行查看,如果是以 Windows 开头的,说明要重新下载安装,这个也和 WIN11 透明效果不起作用有关。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容