高颜值Shell提示符之OhMyPosh安装及使用

22 篇文章 0 订阅
16 篇文章 0 订阅

高颜值Shell提示符之OhMyPosh安装及使用

1. 官网

1. 官网

官网地址:OhMyPosh

GitHub: oh-my-posh-github

2. 是什么?

Oh My Posh 是一个自定义提示引擎,适用于任何能够调整的 shell 带有函数或变量的提示字符串。

2. 特性

1. 颜色

Oh My Posh 使您能够通过使用颜色来定义和呈现提示,从而使用终端的完整颜色集。

2. 定制

轻松调整现有主题或创建自己的主题。从标准细分一直到自定义实施。

3. 便携式

无论您使用哪个 shell,甚至使用多少个 shell,您都可以将配置从一个 shell 和/或机器带到另一个 shell和/或机器,以便在您工作的任何地方获得相同的提示。

3. Windows安装OhMyPosh

1. 安装

打开 PowerShell 提示符并运行以下命令进行安装

winget install JanDeDobbeleer.OhMyPosh -s winget

这将安装下面的功能

  • oh-my-posh.exe- Windows 可执行文件
  • themes- 最新的 Oh My Posh 主题

2. 安装过程

在这里插入图片描述

3.查看是否安装成功

安装后输入命令oh-my-posh,看到帮助命令则表示安装成功

PS C:\Users\23013> oh-my-posh
oh-my-posh is a cross platform tool to render your prompt.
It can use the same configuration everywhere to offer a consistent
experience, regardless of where you are. For a detailed guide
on getting started, have a look at the docs at https://ohmyposh.dev

Usage:
  oh-my-posh [flags]
  oh-my-posh [command]

Available Commands:
  cache       Interact with the oh-my-posh cache
  completion  Generate the autocompletion script for the specified shell
  config      Interact with the config
  debug       Print the prompt in debug mode
  disable     Disable a feature
  enable      Enable a feature
  font        Manage fonts
  get         Get a value from oh-my-posh
  help        Help about any command
  init        Initialize your shell and config
  notice      Print the upgrade notice when a new version is available.
  print       Print the prompt/context
  prompt      Set up the prompt for your shell (deprecated)
  toggle      Toggle a segment on/off
  version     Print the version

Flags:
  -c, --config string   config file path
  -h, --help            help for oh-my-posh
  -i, --init            init (deprecated)
  -s, --shell string    shell (deprecated)
      --version         version

Use "oh-my-posh [command] --help" for more information about a command.
PS C:\Users\23013>

安装成功后接下来配置字体

4.安装字体

现在 Oh My Posh 已安装,您可以继续将终端和 shell 配置为 获取提示,使其看起来与所需完全相同。

Oh My Posh 被设计为使用 Nerd 字体。书字体是流行的字体,经过修补以包含图标。 我们推荐 Meslo LGM NF,但任何 Nerd 字体都应该与标准主题兼容。

要查看 Oh My Posh 中显示的图标,请安装 Nerd 字体,并配置您的终端以使用它。

1. 字体下载

Nerd字体官网: Nerd字体

Nerd字体下载页面: Nerd字体下载,可根据个人爱好选择预览字体后进行下载

2. 安装字体

Oh My Posh 有一个 CLI 来帮助您选择和安装 Nerd 字体。此命令最好以管理员身份执行,以便在整个系统范围内安装字体。 如果您没有管理员权限,则可以通过添加标志来安装字体。 请注意,在使用某些应用程序时,这可能会产生副作用。–user``

oh-my-posh font install

oh-my-posh官方推荐的字体为MesloLG Nerd Font,所以选择Meslo字体进行安装

在这里插入图片描述

下载完成后如下图

在这里插入图片描述

也可选择其他字体安装,如默认选择第一个

在这里插入图片描述

然后回车进行下载安装

在这里插入图片描述

5. 配置字体

文本呈现器: 为确保字形的正确呈现,您需要在终端设置中启用该选项。 有关详细信息,请参阅此处Use the new text renderer ("AtlasEngine")

配置字体的方式有两种:

  • 命令行方式:通过快捷键CTRL + SHIFT + ,打开setting.json文件,然后对其进行相关设置
  • UI界面方式:打开Windows PowerShell–>设置–>windows PowerShell–>其他设置–>外观–>文本–>字体–>将字体选择为MesloGLM Nerd Font即可

1. 配置字体(命令行)

安装 Nerd 字体后,您需要配置 Windows 终端以使用它。这很容易做到 通过修改 Windows 终端设置(默认快捷方式:CTRL + SHIFT + ,)

  1. 使用快捷键CTRL + SHIFT + ,打开setting.json文件,然后找到profiles配置项,并按下面的内容配置
{
    "profiles":
    {
        "defaults":
        {
            "font":
            {
                "face": "MesloLGM Nerd Font"
            }
        }
    }
}
  1. 配置如下

通过快捷键打开的位置如C:\Users\23013\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState,具体内容如下

在这里插入图片描述

2. 配置字体(UI界面)

UI界面安装请查看 WindowsPowerShell中设置Nerd字体-CSDN博客

3.其他字体

如果您对使用 Nerd 字体不感兴趣,您将需要使用不包含任何 Nerd 字体图标的主题。 主题不使用 Nerd 字体图标。minimal

创建自己的主题也😊始终是一种选择

6.主题配置

oh-my-posh安装后,默认的主题位置为C:\用户\用户名\AppData\Local\Programs\oh-my-posh\themes,如:C:\Users\23013\AppData\Local\Programs\oh-my-posh\themes

1.默认主题

默认的主题可在安装文件夹中找到。 可用 PowerShell 对主题进行初始化配置,配置的命令如下。

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/amro.omp.json" | Invoke-Expression

2. 更改PowerShell组织运行本地脚本的策略

PowerShell 能是阻止运行本地脚本。若要解决此问题,请将 PowerShell 设置为 仅要求使用 对远程脚本进行签名,或对配置文件进行签名

以管理员身份打开PowerShell,执行下面命令

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

3. 查看shell类型

oh-my-posh get shell
# 输出如下
powershell

4. 创建配置文件

New-Item -Path $PROFILE -Type File -Force

5. 编辑PowerShell脚本设置主题

编辑 PowerShell 配置文件脚本,可以在首选 PowerShell 版本的变量下找到其位置。例如,使用记事本:$PROFILE

notepad $PROFILE
  1. 打开编辑器后,输入下面内容设置默认的主题
oh-my-posh init pwsh | Invoke-Expression

这意味着每次启动 PowerShell 时,都会自动执行上述命令。该命令中引用的 JSON 文件是 Oh My Posh 的主题配置文件。

  1. 添加保存后,重新加载您的配置文件以使更改生效
. $PROFILE

6. 最终效果

配置文件生效后,效果如下

在这里插入图片描述

7. OhMyPosh更新

打开 PowerShell 提示符并运行以下命令进行更新

winget upgrade JanDeDobbeleer.OhMyPosh -s winget
  • 16
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值