如何在Windows终端中使用电力线,书呆子字体,Cascadia代码,WSL和oh-my-posh进行漂亮提示

I've blogged about Patching the new Cascadia Code to include Powerline Glyphs and other Nerd Fonts for the Windows Terminal but folks have asked very specifically, how do I make my prompt look like that?

我已经在博客中发布了有关修补新的Cascadia代码的信息,以包括Windows终端的电力线字形和其他Nerd字体,但是人们已经非常具体地询问,如何使我的提示看起来像这样?

第一步-获取终端 (Step One - Get the Terminal)

Get Windows Terminal free from the Store. You can also get it from GitHub's releases but I recommend the store because it'll stay up to date automatically.

从商店免费获取Windows Terminal 。 您也可以从GitHub的发行版中获取它,但我推荐商店,因为它会自动保持最新。

Note that if you were an early adopter of the Windows Terminal and you've released updated beyond 0.5, I'd recommend you delete or zero-out your profiles.json and let the Terminal detect and automatically recreate your profiles.json.

请注意,如果您是Windows Terminal的较早采用者,并且发布的更新超过0.5,建议您删除或归零profiles.json并让Terminal检测并自动重新创建profiles.json

Lovely powerline in Windows Terminal

PowerShell的第二步-Posh-Git和Oh-My-Posh (Step Two for PowerShell - Posh-Git and Oh-My-Posh)

Per these directions, install Posh-Git and Oh-My-Posh. This also assumes you've installed Git for Windows.

按照这些指示,安装Posh-Git和Oh-My-Posh。 这还假定您已经安装了Windows版Git

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

Run these commands from PowerShell or PowerShell Core. I recommend PowerShell 6.2.3 or above. You can also use PowerShell on Linux too, so be aware. When you run Install-Module for the first time you'll get a warning that you're downloading and installing stuff from the internet so follow the prompts appropriately.

从PowerShell或PowerShell Core运行这些命令。 我建议使用PowerShell 6.2.3或更高版本。 您也可以在Linux上使用PowerShell,因此请注意。 首次运行Install-Module时,会收到警告,提示您正在从Internet下载和安装内容,因此请按照提示进行操作。

Also get PSReadline if you're on PowerShell Core:

如果您使用的是PowerShell Core,也请获取PSReadline

Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck

Then run "notepad $PROFILE" and add these lines to the end:

然后运行“ notepad $ PROFILE”并将这些行添加到末尾:

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox

Now that word Paradox there is optional. It's actually the name of a theme and you can (and should!) pick the theme that makes you happy and use that theme's name here. I like Agnoster, Paradox, or Fish, myself. Read more over here. https://github.com/JanDeDobbeleer/oh-my-posh

现在这个词悖论是可选的。 它实际上是主题的名称,您可以(并且应该!)选择使您满意的主题,并在此处使用该主题的名称。 我自己喜欢Agnoster,Paradox或Fish。 在这里阅读更多。 https://github.com/JanDeDobbeleer/oh-my-posh

Ubuntu / WSL的第二步 (Step Two for Ubuntu/WSL)

There's a number of choices for Powerline or Powerline-like prompts from Ubuntu. I like Powerline-Go for it's easy defaults.

Ubuntu提供了许多关于Powerline或类似Powerline的提示的选择。 我喜欢Powerline-Go,因为它的默认设置很简单。

I just installed Go, then installed powerline-go with go get.

我刚安装了Go,然后又安装了powerline-go和go get。

sudo apt install golang-go
go get -u github.com/justjanne/powerline-go

Add this to your ~/.bashrc. You may already have a GOPATH so be aware.

将此添加到您的〜/ .bashrc。 您可能已经有一个GOPATH,所以请注意。

GOPATH=$HOME/go
function _update_ps1() {
PS1="$($GOPATH/bin/powerline-go -error $?)"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

GOTCHA: If you are using WSL2, it'll be lightning fast with git prompts if your source code is in your Ubuntu/Linux mount, somewhere under ~/. However, if your source is under /mnt/c or /mnt anywhere, the git calls being made to populate the prompt are super slow. Be warned. Do your Linux source code/git work in the Linux filesystem for speed until WSL2 gets the file system faster under /mnt.

GOTCHA:如果您使用的是WSL2,则源代码位于〜/下的Ubuntu / Linux挂载中时,它将以git提示快速显示。 但是,如果您的源代码位于/ mnt / c或/ mnt下的任何位置,则进行填充提示的git调用将非常慢。 被警告。 在WSL2在/ mnt下更快地获取文件系统之前,您Linux源代码/ git是否在Linux文件系统中工作以提高速度?

At this point your Ubuntu/WSL prompt will look awesome as well!

此时,Ubuntu / WSL提示符也会看起来很棒!

Powerline in WSL

Fonts look weird? Uh oh!

字体看起来很奇怪? 哦!

第三步-获得更好的字体 (Step Three - Get a better font)

If you do all this and you see squares and goofy symbols, it's likely that the font you're using doesn't have the advanced Powerline glyphs. Those glyphs are the ones that make this prompt look so cool!

如果执行所有这些操作,然后看到正方形和愚蠢的符号,则可能是所使用的字体没有高级Powerline字形。 这些字形使此提示看起来很酷!

Weird fonts

At the time of this writing there is active talk of getting Powerline and other Nerd Fonts into Cascadia Code , the new font that ships with Windows Terminal. In the short term, you can get a forked version of Cascadia Code called Delugia Code and download that.

在撰写本文时 ,正在积极讨论将Powerline和其他Nerd字体添加到 Windows终端附带的新字体 Cascadia Code中 在短期内,您可以获取 名为Delugia Code 的Cascadia Code的分支版本 并下载。

Cascadia Code has been updated with a PL (Powerline) Glyph version! Go get it at https://github.com/microsoft/cascadia-code/releases and change the fontFace in your settings.json to "Cascadia Code PL"

卡斯卡迪亚代码 已使用PL(电力线)字形版本进行更新! 在https://github.com/microsoft/cascadia-code/releases上获取它,并将settings.json中的fontFace更改为“ Cascadia Code PL”

"fontFace":  "Cascadia Code PL"

Remember also you can get lots of Nerd Fonts at https://www.nerdfonts.com/, just make sure you get one (or generate one!) that includes PowerLine Glyphs.

还要记住,您还可以在https://www.nerdfonts.com/上获得很多书呆子字体,只需确保获得(或生成一个!)包含PowerLine字形的字体即可。

Have fun!

玩得开心!

翻译自: https://www.hanselman.com/blog/how-to-make-a-pretty-prompt-in-windows-terminal-with-powerline-nerd-fonts-cascadia-code-wsl-and-ohmyposh

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值