2020/03/22, powershell, oh-my-posh
摘要:使用oh-my-posh美化powershell
美化教程參考少數派文章5 個 PowerShell 主題,讓你的 Windows 終端更好看
美化效果圖,此圖是在FluentTerminal下的效果:

准備工作
電腦中需要安裝好git、支持Powerline的字體
git可以去官網下載,如果覺得速度慢,可以考慮在騰訊軟件中搜索下載(速度很快,而且使用普通下載的方式安裝包沒有夾帶私貨)

powerline字體需要去github下載,powerline/fonts地址
而我自己更喜歡使用 更紗黑體,github地址
修改字體
打開powershell,對着標題欄右擊,選擇屬性

安裝主題
執行以下命令安裝posh-git和oh-my-posh兩個模塊,遇到提示選y確認即可,如果下載速度慢,考慮使用小火箭加速
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
新增配置文件
# 如果之前沒有配置文件,就新建一個 PowerShell 配置文件
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
用記事本打開配置文件
notepad $PROFILE
在其中寫入以下內容
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
至此,再重新打開powershell時,會自動加載Paradox主題,一共是
Agnoster、Avit、Darkblood、Fish、Honukai、
Paradox、PowerLine、robbyrussell、Sorin、tehrob這些主題,自己挑選
使用FluentTerminal
去github中下載安裝FluentTerminal,使用ps運行Install.ps1安裝即可
問題解決
1.如果提示git command could not be found要么是git沒裝,要么是裝好沒重啟下,因為git命令加入到環境變量后,重啟才生效
2.提示"無法加載文件...因為在此系統上禁止運行腳本",以管理員方式運行powershell,輸入set-executionpolicy remotesigned命令,回車選y即可
3.在Visual Studio Code的終端中,主題存在行高的問題:

在設置中修改終端的渲染方式即可,我選擇為dom就正常了,如有問題,可以切換其他渲染方式試試

