一、准备工作
首先需要安装Chocolatey:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
关闭脚本禁用:允许Powershell运行脚本:
set-executionpolicy remotesigned
二、安装Oh-my-posh
安装Oh-my-posh,下面命令挨个执行:
choco install ConEmu
Install-Module oh-my-posh -Scope CurrentUser
Install-Module posh-git -Scope CurrentUser
设置Profile脚本:
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 pure
可以看到终端已经变为:
三、设置主题
Oh-my-posh支持以下主题:
Name Type Location
---- ---- --------
Agnoster Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Agnoster.psm1
Avit Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Avit.psm1
Darkblood Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Darkblood.psm1
Fish Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Fish.psm1
Honukai Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Honukai.psm1
Paradox Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Paradox.psm1
Powerlevel10k-Classic Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Powerlevel10k-Classic.psm1
Powerlevel10k-Lean Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Powerlevel10k-Lean.psm1
PowerLine Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\PowerLine.psm1
pure Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\pure.psm1
robbyrussell Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\robbyrussell.psm1
Sorin Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\Sorin.psm1
tehrob Defaults C:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.399\Themes\tehrob.psm1
使用以下命令可以快速切换终端样式(不保存):
Set-Theme <ThemeName>
设置主题:
带Git的样式:
四、设置字体
可以安装一些比较漂亮的字体,比如 Nerd.Font、Fira Code
choco install fira-code
安装字体后,Windows Terminal中配置即可:
{
"defaults":
{
"fontFace" : "'Fira Code', 'Sarasa Term SC Regular', Consolas, 'Courier New', monospace",
"fontSize" : 16,
}
}
五、主题相关配置
使用Show-ThemeColors
命令显示正在使用的主题的配色:
使用 $ThemeSettings
显示当前主题的配置
C:\Windows\System32> $ThemeSettings
PromptSymbols : {UNCSymbol, HomeSymbol, ElevatedSymbol, SegmentSeparatorForwardSymbol...}
Options : {ConsoleTitle, PreserveLastExitCode, OriginSymbols}
CurrentUser : quanzaiyu
CurrentThemeLocation : D:\Users\quanzaiyu\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.478\Themes\Agnoster.psm1
ErrorCount : 0
Colors : {AdminIconForegroundColor, PromptBackgroundColor, PromptHighlightColor, GitLocalChangesColor...}
CurrentHostname : DESKTOP-KR4DIJ4
GitSymbols : {OriginSymbols, LocalWorkingStatusSymbol, LocalDefaultStatusSymbol, BranchUntrackedSymbol...}
MyThemesLocation : D:\Users\quanzaiyu\Documents\WindowsPowerShell\PoshThemes
显示Git样式配置:
$GitPromptSettings