Windows 的 PowerShell 美化教程
记录在一次Windows中升级PowerShell 5.1至PowerShell 7的,并使用 oh my posh 对终端进行美化的折腾过程。
views
| comments
1. 前言#
记录在一次Windows中升级PowerShell 5.1至PowerShell 7的,并使用 oh my posh 对终端进行美化的折腾过程。
2. 升级PowerShell#
参考在 Windows 上安装 PowerShell - PowerShell | Microsoft Learn ↗,在PowerShell中直接运行如下命令安装最新版本
winget install --id Microsoft.Powershell --source winget
powershell安装完成后需要修改默认终端,随便打开一个终端,点击设置,然后将默认启动改为PowerShell 7,如图:
3. 使用 oh my posh 进行美化#
在PowerShell中进行安装:
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))
powershell重启终端,输入oh-my-posh
,若打印如下内容,则说明安装成功:
更改PowerShell的安全策略:以管理员身份运行,然后输入如下内容:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
powershell打开配置文件
notepad $PROFILE
powershell如果提示该文件不存在,可以使用如下命令创建
New-Item -Path $PROFILE -Type File -Force
powershell在打开的配置文件添加以下代码并保存
oh-my-posh init pwsh | Invoke-Expression
plaintext重新打开终端会加载默认主题。
在Nerd Fonts 官网 ↗下载一款自己喜欢的字体,这里以Cousine Nerd Font
为例,解压压缩包后,右键安装所有字体
然后在外观中配置刚刚下载的字体,如图
显示可用的主题:
Get-PoshThemes
powershell记住好自己要切换的主题名称,然后ctrl+左键
打开主题文件夹,如图
打开配置文件:
notepad $PROFILE
powershell配置主题路径,以wholespace
主题为例:
oh-my-posh init pwsh --config "Senv:POSH_THEMES_PATH/wholespace.omp.json" | Invoke-Expression
plaintext重载主题,命令如下
. $PROFILE
powershell当然,还可以在终端外观设置中设置背景和透明度。
4. Vsocde中的乱码配置#
使用的时候发现在VScode中会乱码,安装下面步骤更改终端字体即可:
- 打开设置
- 搜索
Integrated:Font Family
- 将字体修改为上面设置的字体