使用 oh-my-posh 美化教程

windows 终端美化教程

一、更新自带的 PowerShell

  1. 打开 PowerShell,使用 $host 查看版本号

    > $host                                                                              00:12:56
    
    Name             : ConsoleHost
    Version          : 7.3.1  
    InstanceId       : 3714e221-c908-4546-a495-ac44247a7cc5
    UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
    CurrentCulture   : zh-CN
    CurrentUICulture : zh-CN
    PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
    DebuggerEnabled  : True
    IsRunspacePushed : False
    Runspace         : System.Management.Automation.Runspaces.LocalRunspace
    
  2. 一般自带的版本号是 5.1,这时候就需要更新了

    > winget install Microsoft.PowerShell
    

二、安装 OhMyPosh

  1. 安装

    > winget install JanDeDobbeleer.OhMyPosh -s winget
    
  2. 下载字体

    > oh-my-posh font install
    
  3. 更改终端配置文件

    // 添加以下配置
    {
        "profiles":
        {
            "defaults":
            {
                "font":
                {
                    "face": "字体"
                }
            }
        }
    }
    

三、基本配置

  1. 新建配置文件

    > New-Item -Path $PROFILE -Type File -Force
    
  2. 打开配置文件

    > notepad $PROFILE
    
  3. 修改配置文件

    oh-my-posh init pwsh | Invoke-Expression
    
  4. 重载配置文件立即生效

    > .$PROFILE
    

四、更换主题

  1. 查看本地主题

    > Get-PoshThemes
    
  2. 修改配置文件(以 agnosterplus 主题为例)

    主题文件在 C:\Users\XX\AppData\Local\Programs\oh-my-posh\themes

    # 打开配置文件
    > notepad $PROFILE
    
    # 填写主题文件 agnosterplus.omp.json 的路径
    oh-my-posh init pwsh --config '文件路径' | Invoke-Expression
    
  3. 重载配置文件立即生效

    > .$PROFILE
    

五、最终效果

最终效果

posted @ 2023-02-07 00:53  HypoPine  阅读(434)  评论(0编辑  收藏  举报