继续

Oh-my-posh

第一次看到这个名字的时候,感觉挺亲切的~

毕竟每次 LInux 使用的时候 oh-my-zsh 都是必装的

贴上官网:https://ohmyposh.dev/docs

安装

手动安装就不说了,可以直接在 microsoft store 中安装即可

这里记录下 scoop 的命令

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

字体

主题里面用到了各种的图标,所以需要用到专门的字体: Nerd Font

进入这个字体网站后可以找自己喜欢的下载,比如我们熟悉的:JetBrainsMono Nerd Font

这个就是基于 JetBrainsMono 生成的支持 icon 的 Nerd 字体

下载后安装(下载后是个压缩包,解压后全选字体,右键安装, 可安装全部)

安装后,可更改 windows terminal 的字体设置

打开 windows terminal 的设置(ctrl + shift + 逗号)

差不多这个位置:

image-20230827000856863

defaults 后面大括号里面填上:

"font":
{
    "face": "JetBrainsMono Nerd Font"
}

改完后这样:

image-20230827001048125

新装的字体可能需要重启电脑,才可以用

如果感觉字体有点儿大的话,可以改下字体大小

还是刚才那里:

"font":
{
    "face": "JetBrainsMono Nerd Font",
    "size": 10
}

主题

使用 oh-my-posh,需要先创建一个配置文件

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

执行后,会生成这个文件:C:\Users\chunxiao.li\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

可以通过以下命令直接用 vscode 打开

code $profile

$profile就指的是上述文件

在文件中写入:

oh-my-posh init pwsh | Invoke-Expression

这个时候已经可以看到效果了,需要重新打开 windows terminal

如果不喜欢默认主题,那就去找一个自己喜欢的

先将所有主题下载下来

Get-PoshThemes

等下载完,会在控制台最下面打出来主题所在目录

比如我的:

C:\Users\chunxiao.li\AppData\Local\Programs\oh-my-posh\themes

并且会提示如果想用指定主题怎么用:

oh-my-posh init pwsh --config 'C:\Users\chunxiao.li\AppData\Local\Programs\oh-my-posh\themes\jandedobbeleer.omp.json' | Invoke-Expression

对,就是用这个替换刚才的按个 $profile 文件内容

想换不同的主题就去把替换成对应的 .omp.json

提供官方预览主题的地址:

https://ohmyposh.dev/docs/themes

推荐下我现在用的:

#oh-my-posh init pwsh --config 'C:\Users\chunxiao.li\AppData\Local\Programs\oh-my-posh\themes\1_shell.omp.json' | Invoke-Expression
oh-my-posh init pwsh --config 'C:\Users\chunxiao.li\AppData\Local\Programs\oh-my-posh\themes\craver.omp.json' | Invoke-Expression

image-20230827003059959