PowerShell 7安装和美化

一、什么是poweshell7

PowerShell 7 是新一代、跨平台、开源的命令行工具和脚本语言。

相比与Windows PowerShell,它的性能和兼容性更强。支持Windows, macOS, Linux三个平台。

安装:

复制代码
winget install --id Microsoft.PowerShell

或者访问官方网页:在 Windows 上安装 PowerShell 7 - PowerShell | Microsoft Learn

二、美化

1.安装posh-git 模块

功能:显示 Git 状态信息,并提供 Git 命令的自动补全。

bash 复制代码
Install-Module posh-git

2.安装oh-my-posh模块

首页 |哦,我的 Posh --- Home | Oh My Posh

功能:主题美化

bash 复制代码
winget install JanDeDobbeleer.OhMyPosh -s winget

安装成功验证:

3.初始化主题配置:

bash 复制代码
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression

如下:

4.更换主题

Share theme | Oh My Posh在主题页挑选自己喜欢的主题。

在终端输入notepad PROFILE,把主题名称换成自己选择的就行了,然后再. PROFILE重启更新。如果找不到环境变量就使用绝对路径。

5.安装字体

bash 复制代码
oh-my-posh font install

在终端设置中替换字体,我选的是MesloLGM Nerd Font Mono。

6.美化文件夹

bash 复制代码
Install-Module -Name Terminal-Icons -Repository PSGallery

打开配置文件

复制代码
notepad $PROFILE

最后一行粘贴

复制代码
Import-Module -Name Terminal-Icons

重载生效

复制代码
. $PROFILE

效果:

参考:我与《Oh My Posh》和 Windows 终端的终极 PowerShell 提示------Scott Hanselman 的博客 --- My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal - Scott Hanselman's Blog