Powershell + windows Terminal最簡單的美化

網(wǎng)上一大堆美化教程,啰里啰唆,還講不清,并且一堆錯誤

oh-my-posh2(該方法已廢止,請不要使用)

第一步安裝模塊

powershell 管理員身份運行,并執(zhí)行以下。

##允許執(zhí)行腳本
set-executionpolicy remotesigned
Install-module PSReadline
Install-Module posh-git
Install-Module oh-my-posh
Install-Module DirColors

第二步 導(dǎo)入模塊

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

但此時,只應(yīng)用到當(dāng)前,下次打開還是老樣子,這樣,我們就給加個配置文件

第三步 配置

首先記事本打開
notepad $profile
接著輸入如下內(nèi)容并保存

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

第四步 安裝個好看的字體

安裝字體是必須的,否則可能出現(xiàn)亂碼。這里既然用的Theme powerLine,那我們就下powerLine字體
powerline/fonts: Patched fonts for Powerline users. (github.com)
下載以后,找到DejaVu Sans Mono for Powerline.ttf安裝
并在windows terminal設(shè)置里設(shè)置好該字體

i字體設(shè)置

第五步 給windows terminal選個合適的配色

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

image.png

或者直接在面板里選擇

我的成品


image.png

oh-my-posh3(新教程)

windows 10還沒有自帶terminal,可以到這里下載
Releases · microsoft/terminal (github.com)

win11已經(jīng)自己帶了

以下是新教程,只針對
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

保存

但是,這個官方推薦的默認(rèn)主題非常慢,加載還總出錯,我推薦選其他的

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

https://ohmyposh.dev/docs/themes

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

比之前簡單多了

注意,若出現(xiàn)powershell無權(quán)限執(zhí)行腳本的問題。可以如下處理

1.查看當(dāng)前權(quán)限:

Get-ExecutionPolicy

2.設(shè)定權(quán)限(必須右鍵管理員權(quán)限打開powershell)

Set-ExecutionPolicy RemoteSigned

PowerShell有4種腳本權(quán)限:

Restricted: 默認(rèn)的設(shè)置,不允許任何script運行。
AllSigned: 只能運行經(jīng)過數(shù)字證書簽名的script。
RemoteSigned: 運行本地的script不需要數(shù)字簽名,但是運行從網(wǎng)絡(luò)上下載的script必須要有數(shù)字簽名。
Unrestricted: 允許所有的script運行。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容