Powershell + windows Terminal最简单的美化

网上一大堆美化教程,啰里啰唆,还讲不清,并且一堆错误

oh-my-posh2(该方法已废止,请不要使用)

第一步安装模块

powershell 管理员身份运行,并执行以下。

##允许执行脚本
set-executionpolicy remotesigned
Install-module PSReadline
Install-Module posh-git
Install-Module oh-my-posh
Install-Module DirColors

第二步 导入模块

Import-Module PSReadline
Import-Module DirColors
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme powerLine

但此时,只应用到当前,下次打开还是老样子,这样,我们就给加个配置文件

第三步 配置

首先记事本打开
notepad $profile
接着输入如下内容并保存

Import-Module PSReadline
Import-Module DirColors
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme powerLine

第四步 安装个好看的字体

安装字体是必须的,否则可能出现乱码。这里既然用的Theme powerLine,那我们就下powerLine字体
powerline/fonts: Patched fonts for Powerline users. (github.com)
下载以后,找到DejaVu Sans Mono for Powerline.ttf安装
并在windows terminal设置里设置好该字体

i字体设置

第五步 给windows terminal选个合适的配色

在Terminal的配置json文件中插入
"colorScheme": "One Half Dark",

image.png

或者直接在面板里选择

我的成品


image.png

oh-my-posh3(新教程)

windows 10还没有自带terminal,可以到这里下载
Releases · microsoft/terminal (github.com)

win11已经自己带了

以下是新教程,只针对
oh-my-posh3

直接在微软商店搜索oh my posh下载
或者,

winget install JanDeDobbeleer.OhMyPosh -s winget

This installs a couple of things:

  • oh-my-posh.exe - Windows executable
  • themes - The latest Oh My Posh themes

如果以上方法都不能安装,请到github下载
Releases · JanDeDobbeleer/oh-my-posh (github.com)

然后terminal 重启

先下载一个字体
https://www.nerdfonts.com/font-downloads

个人推荐


image.png

和之前一样,在terminal打开

notepad $profile

输入

oh-my-posh init pwsh | Invoke-Expression

保存

但是,这个官方推荐的默认主题非常慢,加载还总出错,我推荐选其他的

自己到官方看看哪个符合心意?

https://ohmyposh.dev/docs/themes

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/unicorn.omp.json" | Invoke-Expression
image.png

比之前简单多了

注意,若出现powershell无权限执行脚本的问题。可以如下处理

1.查看当前权限:

Get-ExecutionPolicy

2.设定权限(必须右键管理员权限打开powershell)

Set-ExecutionPolicy RemoteSigned

PowerShell有4种脚本权限:

Restricted: 默认的设置,不允许任何script运行。
AllSigned: 只能运行经过数字证书签名的script。
RemoteSigned: 运行本地的script不需要数字签名,但是运行从网络上下载的script必须要有数字签名。
Unrestricted: 允许所有的script运行。

你可能感兴趣的:(Powershell + windows Terminal最简单的美化)