Windows terminal 安装配置 oh-my-posh
适用于 Windows terminal + powershell
安装 oh-my-posh
Microsoft Store 中搜索并安装:oh-my-posh
by jandedobbeleer
使用图标字体
Nerd Fonts - Iconic font aggregator, glyphs/icons collection, & fonts patcher
去这里下载一个自己喜欢的字体,并配置 windows terminal power shell profile 使用该字体。
配置 profile
判断当前的 shell 类型:oh-my-posh get shell
PS C:\Users\luyang\Desktop> oh-my-posh get shell
powershell
修改配置文件:
notepad $PROFILE
添加如下内容:
oh-my-posh init pwsh | Invoke-Expression
如果 notepad $PROFILE
报错,说配置文件不存在需要自己创建一个:
New-Item -Path $PROFILE -Type File -Force
加载配置:
. $PROFILE
Q&A
运行报错:
Windows PowerShell
版权所有(C) Microsoft Corporation。保留所有权利。
安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows
. : 无法加载文件 C:\Users\luyang\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,因为在此系统上禁止运行脚
本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\luyang\Documents\WindowsPowerShell\Microsoft.PowerShell_pr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
原因:PowerShell 默认禁止运行脚本,PowerShell 默认禁止运行脚本;
Restricted
表示在 PowerShell 中运行脚本是禁止的
PS C:\Users\luyang> get-ExecutionPolicy
Restricted
解决方案:
以管理员身份运行 windows PowerShell,执行如下命令,并选择 Y
, 之后再运行 PowerShell 即可恢复正常。
set-ExecutionPolicy RemoteSigned
PS C:\WINDOWS\system32> set-ExecutionPolicy RemoteSigned
执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): Y
PS C:\WINDOWS\system32>