Oh-my-Posh V3更新说明

经过这几天对 Windows Terminal 美化的研究,发现 Oh-my-Posh 从 V2 升级到 V3产生了非常多影响,且这些影响会导致之前的文档、教程等内容失效,或是无法达成预期的目标,因此这篇博文本人会取 Oh-my-Posh 的最新文档相关的部分进行翻译转载,一方面供最近美化 Windows Terminal 的朋友进行参考,一方面作为本人近几期博文教程的参考。

Introduction 概述

Oh my Posh is a custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable.

Oh my Posh 是一个任何 shell 都可以使用的自定义提示符引擎,它可以将一个提示符字符串转换为一个函数或变量。

Oh my Posh 3 vs Oh my Posh 2

Oh my Posh 3 is the offspring of Oh my Posh, a prompt theme engine for PowerShell. Oh my Posh started out by being inspired from tools like oh my zsh when nothing was available specifically for PowerShell.

Oh my Posh 3 是最新一代的 Oh my Posh(PowerShell的即时主题引擎)。Oh my Posh 最初是受 Oh-my-zsh 之类的工具启发而来的,而当时还没有专门针对PowerShell的类似工具。

Over the years, I switched operating system/main shell quite a lot, even on Windows via the WSL. This made it so that my prompt wasn’t portable enough, I wanted the same visual/functional experience regardless of the shell I was working in. Hello world Oh my Posh 3!

多年来,即使 Windows 上有 WSL (Windows Subsystem for Linux, 适用于Windows的Linux子系统1),我也换过很多操作系统 / main shell。这样就使得我的提示符不够便携,因为我希望无论我使用哪种 shell ,我都能获得相同的视觉 以及 功能的体验。就这样, Oh-my-Posh 3 诞生了。

Upgrading 更新

Just like V2, V3 is available in the PowerShell gallery. Due to its nature, it’s only available as a prerelease while we work out the kinks and get it on par with V2.

和第二版一样, PowerShell 库也提供了第三版的 Oh-my-Posh 。由于其性质,在我们解决问题并使其与V2保持一致时,它只能作为预发行版使用。

V2’s problem statement V2的问题陈述

V2 has Powershell module files as themes. That way of working was inspired from oh-my-zsh and other prompt rendering tools, but that approach has a few important downsides.

V2以Powershell模块文件为主题。这种工作方式受到了oh-my-zsh和其他即时渲染工具的启发,但是这种方法有一些重要的缺点。

  • hard to extend/adjust when you’re not proficient
  • 如果你(对PowerShell的各种操作)并不熟练,那么它很难扩展或调整
  • the need to expose a lot of functions/settings to allow ease of personalization
  • 需要公开许多功能和设置以简化个性化设置
  • limited to Powershell
  • 仅限 PowerShell

Enter V3 跨入第三版

This bring us to the first change, to allow a cross platform experience, Oh My Posh V3 is written entirely in Go. That way, cross platform binaries can be shipped which render the same prompt using the same config anywhere.

这就带来了我们的第一个变化,即允许跨平台体验,Oh My Posh V3 全部用 Go 语言编写。这样一来,跨平台的二进制文件就可以发布了,它可以在任何地方使用相同的配置来呈现相同的提示。

The configuration is changed from $ThemeSettings towards a .json file that only contains the configuration for the blocks and segments you want to render. See concept for more context on that part.

配置从更改为仅包含要渲染的块和段的配置 $ThemeSettings 的 .json 文件。有关更多上下文,请参见概述部分

Let’s have a look at the V2 commands and how to move towards V3.

让我们看一下V2命令以及如何过渡到V3。

Import 导入

Stays the same! Alright. All you need to do is update to the beta.

保持不变?好吧。您需要做的就是 “更新beta版”

Update-Module -Name oh-my-posh -AllowPrerelease -Scope CurrentUser

Configuration 配置

Here we have a few options. If you’re using an out-of-the box theme, you can simply change the current command to the new one, provided your V2 theme has already been added to V3.

在这里,我们有一些选择。如果您使用的是预设的主题,则只需将当前命令更改为新命令即可,前提是您的V2主题已添加到V3中。

I use an out-of-the-box theme 我使用预设主题

Change the current prompt setting function to the new one.

将现有的提示符设置语句改为新的。

# Set-Theme Agnoster
Set-PoshPrompt -Theme agnoster

I use a custom theme/settings 我使用自定义主题 / 设置

The first thing to do is to look for the theme you based your theme on. If you don’t remember which one, preview them all and take the one closest to yours.

要做的第一件事是寻找您曾经作为基础的主题。如果您忘记了哪一个,请预览所有内容,然后选择最接近的一个。

Get-PoshThemes

If you see one you like, set it, then export its config so you can customize/extend the blocks and segments.

如果看到自己喜欢的一个,请对其进行设置,然后导出其配置,以便可以自定义/扩展块和段。

Set-PoshPrompt -Theme jandedobbeleer
Export-PoshTheme -FilePath ~/.oh-my-posh.omp.json

Adjust the config (~/.oh-my-posh.omp.json) to your liking by going through the configuration guide. Set your custom theme and enjoy.

通过阅读配置指南,根据自己的喜好调整配置(~/.oh-my-posh.omp.json)。设置您的自定义主题并享受。

Set-PoshPrompt -Theme  ~/.oh-my-posh.omp.json

I have no idea just yet 我还未做好决定

Great! There’s an option for that too. You can easily list all available themes and pick the one you like best.

好的吧。。也有一个选择。您可以轻松列出所有可用的主题,然后选择最喜欢的主题。

Get-PoshThemes

Choose and set the one you like.

选一个你喜欢的设置成自己的主题。

Set-PoshPrompt -Theme jandedobbeleer

Installation 安装

1. Setup your terminal 设置您的终端

Windows

Terminal 终端

While Oh my Posh works on the standard terminal, we advise using the Windows Terminal.

当Oh my Posh在标准终端上工作时,建议您使用 Windows Terminal。

Font 字体

To see the icons displayed in Oh my Posh, install and configure your terminal to use a powerline enabled font. The fonts we use are patched by Nerd Fonts, which offer a maximum of icons you can use.

要查看 “Oh-my-Posh” 中显示的图标,请安装并配置终端以确认启用了powerline的字体。我们使用的字体 Nerd Fonts,该字体提供了最多可使用的图标。

Oh my Posh was designed using Meslo LGM NF, but any Nerd Font should be compatible with the standard themes.

Oh-my-Posh 是基于 Meslo LGM NF2 字体设计的,但是任何 Nerd 字体都会兼容标准主题。

! ! ! WINDOWS FONTS Windows 字体 ! ! !
Make sure to install fonts system wide to avoid seeing rectangles in your terminal. See this thread for more context.
确保在全系统范围内安装字体,以避免在终端中看到矩形(乱码)。更多信息见

2. Install Oh my Posh 安装 Oh my Posh

powershell

A Powershell module is available for easy installation.

PowerShell模块可供安装。

Installation 安装

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

Usage 用法

Show all themes 显示所有主题

To display every available theme in the current directory, use the following cmdlet.

若要显示当前目录中的每个可用主题,请使用以下cmdlet。

Get-PoshThemes

Windows

A Scoop package is available for easy installation.

Scoop包可供安装。

Installation 安装

scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json

This installs a couple of things:

这将安装一些内容:

  • oh-my-posh.exe - Windows executable, added to your $PATH
  • oh-my-posh.exe -Windows可执行文件,已添加到您的 $PATH
  • oh-my-posh-wsl - Linux executable, added to your $PATH for use in the WSL
  • oh-my-posh-wsl-Linux可执行文件,已添加到您$PATH的WSL中以供使用
  • themes - The latest Oh my Posh themes
  • themes -最新的oh-my-posh主题

If you want to use a standard theme, you can find them in ~\scoop\apps\oh-my-posh\current\themes\ , referencing them as such will always keep them compatible with the binary when updating Oh my Posh.

如果要使用标准主题,则可以在中找到它们 ~\scoop\apps\oh-my-posh\current\themes\ ,因此在更新Oh my Posh时始终引用它们会始终与二进制文件兼容。

Preview the themes 预览主题

Get-ChildItem -Path "$(scoop prefix oh-my-posh)/themes/*" -Include '*.omp.json' | Sort-Object Name | ForEach-Object -Process {
    $esc = [char]27
    Write-Host ""
    Write-Host "$esc[1m$($_.BaseName)$esc[0m"
    Write-Host ""
    & "C:\tools\oh-my-posh.exe" -config $($_.FullName) -pwd $PWD
    Write-Host ""
}

Update 更新

scoop update oh-my-posh

3. Replace your existing prompt 更换现有的提示符

powershell

Edit $PROFILE in your preferred PowerShell version and add the following line.

在您默认的PowerShell版本下编辑$PROFILE并添加以下行。

  • module

Autocompletion is available so it will loop through all available themes.

自动补全功能可用,因此它将遍历所有可用主题。

Set-PoshPrompt -Theme jandedobbeleer

Once added, reload your profile for the changes to take effect.

添加后,重新加载您的配置文件以使更改生效。

. $profile

5. Next steps 接下来…

At this point you’re good to go. The jandedobbeleer.omp.json theme displays most common use-cases in your prompt so 9/10 you’ll be more than happy with it. However, if you want to explore additional functionality, going through the additional steps below will help you get started.

在这一点上你很好。该jandedobbeleer.omp.json主题在您的提示中显示最常见的用例,因此9/10会让您非常满意。但是,如果您想探索其他功能,请执行以下其他步骤将帮助您入门。

Change the theme 更改主题

We downloaded all the themes and set jandedobbeleer.omp.json as the one to use. However, there are a lot more to be discovered and maybe there are some you like better.

我们下载了所有主题并将其设置jandedobbeleer.omp.json为可使用的主题。但是,还有更多发现的地方,也许还有一些您更喜欢的地方。

Adjust your configuration to use any other theme from the folder we created (~/.poshthemes).

调整配置以使用我们创建的文件夹(~/.poshthemes)中的任何其他主题。

Override the theme settings 覆盖的主题设置

Maybe there’s a theme you like, but you don’t fancy the colors. Or, maybe there’s a segment you want to tweak/add, or replace some of the icons with a different one. Whatever the case, read through all available options first, by starting with the configuration guide.

也许有一个您喜欢的主题,但是您不喜欢这些颜色。或者,也许您想调整/添加一个段,或者用其他图标替换某些图标。无论如何,请先从配置指南开始通读所有可用选项。

powershell module

You can output the current theme to its JSON representation which can be used to tweak and store as your custom theme.

您可以将当前主题输出到其JSON表示形式,以用于调整和存储为自定义主题。

Export-PoshTheme -FilePath ~/.mytheme.omp.json

Once you’re done editing, adjust your $PROFILE to use your newly created theme.

完成编辑后,请调整$PROFILE为使用新创建的主题。

Set-PoshPrompt -Theme ~/.mytheme.omp.json

Themes

👆点击链接预览主题。


  1. 这里的翻译来自 Windows 系统中的翻译,个人认为容易引起歧义,个人更倾向与翻译成百度百科中 “Windows 下的 Linux 子系统”↩︎

  2. 这个文件下载比较慢,之后我会放出下载链接↩︎

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值