Windows Terminal 美化

Windows Terminal 我已经使用了很长一段时间了,美化也用了很长一段时间,但是有个问题,每次一设置完就可以很长一段时间不用管了,所以每次操作系统或者换电脑时很费功夫,所以先记录下来方便之后使用

前期准备

  • 安装 Windows Terminal

    win 11 自带可以忽略,win 10 可以到应用商店上搜索 Windows Terminal 安装即可

  • 安装 PowerShell 7

    自带的 PowerShell 好像是 5 ,不过不用管了,直接到应用商店搜索 PowerShell 安装即可

  • 设置权限

    PowerShell 想要执行脚本需要先设置执行权限

1
Set-ExecutionPolicy RemoteSigned -scope CurrentUser

开始美化

这里是直接使用 PowerShell 进行安装,如果需要用到 scoop 可以执行以下命令下载 scoop

1
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
  • 安装 posh-git
1
Install-Module posh-git -Scope CurrentUser
  • 安装 oh-my-posh
1
Install-Module oh-my-posh -Scope CurrentUser
  • 设置主题

    我这里使用的是 M365Princess 这款主题

1
Set-PoshPrompt M365Princess
  • 其他主题

    如果需要使用其他主题,有两种方式获取,可以到 oh-my-posh 官网查看 https://ohmyposh.dev/docs/themes , 或者执行以下命令

1
Get-PoshThemes
  • 安装字体

    设置完主题以后可能会出现乱码的情况,只需要安装一款合适的字体即可,推荐到 https://www.nerdfonts.com/ 进行挑选安装

  • 更改字体

  • 自动设置主题

    当窗口关闭以后主题就消失了,所以需要写一个让 PowerShell 每次启动后都自动设置好主题的脚本

    1
    notepad $PROFILE	# 用记事本打开

    然后写入以下内容

    1
    Set-PoshPrompt M365Princess

    之后每次启动都会自动设置号主体了

参考自以下内容
Windows Terminal 主题美化
Tried to install oh-my-posh but it tells me that “the term is not recognized as…”