1.检查和更新 powershell
# 检查 powershell 版本
$PSVersionTable.PSVersion
# 不够新可以安装新版本
winget install Microsoft.PowerShell
2.检查和安装 Windows Terminal
Windows 11 已默认内置了 Windows Terminal
win10 可以去这里 下载最新版 ( 2024年5月17日)
上面一步骤下载不了的 可以在 这里下载
3.安装必要组件
powershell 运行
# 设置策略
Set-ExecutionPolicy -ExecutionPolicy Remotesigned -Scope CurrentUser
# 检查 $PROFILE 文件是否存在
# 提示:此文件是powershell 打开会默认执行的一个文件
# 执行此代码 显示 true 则 不需要进行创建 否则 需要执行 下面的创建 $PROFILE 文件的代码
Test-Path -Path $PROFILE
# 创建$PROFILE文件
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
Install-Module -Name PackageManagement -Repository PSGallery -Force
Install-Module -Name PowerShellGet -Repository PSGallery -Force
# 安装 PSReadLine
install-module -Name PSReadLine -AllowPrerelease -Force
4.安装 ohmyposh
官方连接在这里 、官方支持 多种安装方式.。
scoop安装方式
由于我有安装scoop 所以直接 powershell 运行。如果没有scoop 也很简单 安装一下就好.
tips: scoop 也支持安装 vim aria2 等常用命令。让你熟练记住 linux 命令。
# 安装scoop 命令
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
# 使用scoop 安装 oh-my-posh
scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json
# 安装 posh-git
Install-Module -Name posh-git -Scope CurrentUser
5.安装字体
带图标字体下载 注意这里是 Nerd 结尾的是带图标的
我这里也提供一个 点击此处 下载
下载后解压 后 选中所有 ttf 结尾的文件 右键 -> 为所有用户安装 然后等待安装完毕
6.安装图标库
# powershell 执行
Install-Module -Name Terminal-Icons -Repository PSGallery
7.配置 $profile文件
这里就可以使用windows Terminal 打开 输入一下命令
# 打开配置文件,优先使用 vscode ,其次会使用记事本打开
notepad $PROFILE
这里输入后会弹出 一个文件。
这里是我的 notepad $PROFILE 打开的文件内容 直接可以粘贴进去保存即可
Import-Module posh-git
Import-Module PSReadLine
Import-Module oh-my-posh
# 导入图标库
Import-Module -Name Terminal-Icons
# 这几个主题都很好看,实际看你喜欢哪个
# oh-my-posh init pwsh --config 'C:\Users\{替换成你电脑用户名}\AppData\Local\Programs\oh-my-posh\themes\1_shell.omp.json' | Invoke-Expression
# oh-my-posh init pwsh --config 'C:\Users\{替换成你电脑用户名}\AppData\Local\Programs\oh-my-posh\themes\easy-term.omp.json' | Invoke-Expression
# oh-my-posh init pwsh --config 'C:\Users\{替换成你电脑用户名}\AppData\Local\Programs\oh-my-posh\themes\kali.omp.json' | Invoke-Expression
# oh-my-posh init pwsh --config 'C:\Users\{替换成你电脑用户名}\AppData\Local\Programs\oh-my-posh\themes\sorin.omp.json' | Invoke-Expression
# oh-my-posh init pwsh --config 'C:\Users\{替换成你电脑用户名}\AppData\Local\Programs\oh-my-posh\themes\paradox.omp.json' | Invoke-Expression
oh-my-posh init pwsh --config 'C:\Users\{替换成你电脑用户名}\AppData\Local\Programs\oh-my-posh\themes\kushal.omp.json' | Invoke-Expression
# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History
# 自动补全
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -Predictionviewstyle Listview
Set-PSReadLineOption -EditMode Windows
然后重新打开 window terminal 即可获得 美化 主题
常见问题
问题示例:Install-Module : 找不到与参数名称“AllowPrerelease”匹配的参数。
Did you complete the steps prior to this one? Specifically:
Install-Module -Name PackageManagement -Repository PSGallery -Force
Install-Module -Name PowerShellGet -Repository PSGallery -Force
# Then restart shell, Then enter
Install-Module -Name Az.StorageSync -AllowPrerelease -AllowClobber -Force
如果图标乱码 可能是:
1.图标字体没有导入
参照 上面的 第 6 第 7 步骤。
2.window-terminal 中没有 设置默认字体
window-terminal 中没有 设置默认字体。(解决方法)
windwo-terminal 中打开 设置 ---> Windows PowerShell --> 外观 ---> 字体 选择 CaskayDiaCove NF 点击保存更改即可
好了可以开心的玩 (装)耍(13)了