使用Oh-my-posh配置Powershell

1 安装所需软件、字体

1.1 安装终端(用于设置字体)

store搜索终端终端

1.2 安装Powershell7

PowerShell 7.0 为开放源代码、跨平台 (Windows、macOS 和 Linux) 的 PowerShell版本,构建来管理异质环境和混合式云端。
在此版本中,我们引进了许多新功能,包括:
使用进行管线平行处理ForEach-Object -Parallel 添加运算符 :
三元运算符 :a ? b : c
管线链接运算符: 和||&& Null
条件运算子: 和 ???=
简化的动态错误查看和 Cmdlet,可让您更轻松地调查错误Get-Error
兼容性阶层,可让用户在隐含的 Windows PowerShell 会话中导入模块 自动新版本通知
能够直接从 PowerShell 7调用 DSC 资源 (实验性)

store搜索Powershell
Powershell
不会覆盖安装

1.3 安装nerd字体

访问nerd官网
https://www.nerdfonts.com/font-downloads

在这里插入图片描述
选择3270 Nerd Font下载
本地打开3270文件夹,排序方式选择类型,
选择所有ttf(TrueType)文件或otf(OpenType)文件右键安装安装nerd

1.4 安装scoop

打开终端,选择Powershell.(新安装)

Set-ExecutionPolicy RemoteSigned -scope CurrentUser
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

1.5 安装sudo和aria2(用于scoop下载加速和断点续传)

scoop install aria2
scoop install sudo

1.6 安装oh-my-posh

scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json

2 配置终端样式和字体

2.1 配置字体

终端打开Powershell,Ctrl + Shift + , 打开json文件,把

 "profiles": 
    {
        "defaults": {},

改为

 "profiles": 
    {
        "defaults": 
        {
            "font": 
            {
                "face": "3270Narrow NF"
            }
        },

2.2 默认主题

终端Powershell,

notepad $profile
# Microsoft.Powershell_profile.ps1 - 记事本
oh-my-posh init pwsh | Invoke-Expression
#保存退出
.$profile

即可显示默认主题
在这里插入图片描述

2.3 自定义主题

终端Powershell
将xxx替换为用户名
开始菜单搜索环境变量,打开,按照图片复制POSH_THEMES_PATH的值
在这里插入图片描述

Get-PoshThemes
#找到想要的主题
notepad $profile
# Microsoft.Powershell_profile.ps1 - 记事本
# 将之前的内容间加入oh-my-posh init pwsh | Invoke-Expression的标记处
#                                      ^
# 加入 --config C:\Users\xxx\scoop\apps\oh-my-posh\current\themes\喜欢的主题名称.omp.json
# 也是  复制的PATH\喜欢的主题名称.omp.json
oh-my-posh init pwsh --config C:\Users\xxx\scoop\apps\oh-my-posh\current\themes\jandedobbeleer.omp.json| Invoke-Expression
#保存退出
.$profile

自此,Powershell美化完成
Oh-my-posh配置完成

============================================
如果此时安装完成后提示

The term ‘oh-my-posh’ is not recognized as a name of a cmdlet, function, script file, or 
executable program. Check the spelling of the name, or if a path was included, verify that 
the path is correct and try again.

请重启电脑,然后生效。

3 为Windows11托管命令行

在这里插入图片描述

4 参考

https://zhuanlan.zhihu.com/p/444165353
https://blog.csdn.net/weixin_44490152/article/details/113890026
https://zhuanlan.zhihu.com/p/354603010


版权声明:本文为gavinliu266原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。