第一步

windows 应用商店安装 WindowsTerminal

image-20230826193816724

确保自己电脑有 PowerShell, 或者去下载一个也是在应用商店

image-20230826193848906

安装字体否则一些显示有问题:字体上传到了云端可以去拉取获取下载链接:https://ohmyposh.dev/docs/installation/fonts 点击 Meslo LGM NF 即可下载字体包

# 安装 oh-my-posh
winget install JanDeDobbeleer.OhMyPosh -s winget
# 使用的是哪个 shell
oh-my-posh get shell
# 直接加载:
& ([ScriptBlock]::Create((oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\night-owl.omp.json" --print) -join "`n"))
# 编辑 PowerShell 配置文件脚本,每次启动之后自动加载
notepad $PROFILE
# 当上述命令出错时,请确保先创建配置文件
New-Item -Path $PROFILE -Type File -Force
# 在配置文件里添加以下行:
& ([ScriptBlock]::Create((oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\night-owl.omp.json" --print) -join "`n"))
或者添加这行:
oh-my-posh init pwsh --config '$env:POSH_THEMES_PATH\night-owl.omp.json' | Invoke-Expression
# 重新加载配置文件以使更改生效
. $PROFILE
# 查看所有 themes:
Get-PoshThemes
#运行上面命令后,最后 3 行显示如下:
# ---theme 存放的位置:
Themes location: C:\Users\admin\AppData\Local\Programs\oh-my-posh\themes
# --- 如果输入 $profile, 得出的路径跟以下是一致的:
To change your theme, adjust the init script in C:\Users\admin\Documents\PowerShell\Microsoft.PowerShell_profile.ps1.
# --- 之前 $profile 配置文件,也可以改成以下这句(之前这句,向防病毒软件添加例外)里面路径写自己对应的
oh-my-posh init pwsh --config 'C:\Users\Administrator\AppData\Local\Programs\oh-my-posh\themes\night-owl.omp.json' | Invoke-Expression
# 安装文件图标库
Install-Module -Name Terminal-Icons -Repository PSGallery
#使用图标,可以把以下这条命令加到 $PROFILE 里(保存,.$profile 使生效),单独运行就是一次性:
Import-Module -Name Terminal-Icons
#BONUS:
# 设置随机主题:
# 在 powershell 输入 code $profile,输入下面的脚本命令:
oh-my-posh init pwsh --config 'C:\Users\Administrator\AppData\Local\Programs\oh-my-posh\themes\night-owl.omp.json' | Invoke-Expression

如果命令操作中出现创建文件的错误问题而无法解决则自己去对应的路径下创建一个如下:然后将下面配置信息写入

oh-my-posh init pwsh --config 'C:\Users\Administrator\AppData\Local\Programs\oh-my-posh\themes\night-owl.omp.json' | Invoke-Expression
  • 注意:里面的路径按照自己执行命令:Get-PoshThemes 的时候最后一行看到的填写打开路径的目录可以按照自己喜欢的样式改。

image-20230826193942959

最后就是 Windows Terminal 的配置了

image-20230826194133851image-20230826194150186

image-20230826194225862

image-20230827165110165

效果

image-20230828092941987

也可以配合着 neofetch 使用

oh-my-posh init pwsh --config 'C:\Users\Administrator\AppData\Local\Programs\oh-my-posh\themes\night-owl.omp.json' | Invoke-Expression
neofetch --ascii_distro Mac