[TOC]
# Windows Terminal 加 powershell7 美化命令行
# 安裝字體
```
scoop install -g nerd-fonts/Cascadia-Code
```
# posh-git 與 oh-my-posh
~~~powershell
> Install-Module posh-git -Scope CurrentUser
> Install-Module oh-my-posh -Scope CurrentUser
> Set-PoshPrompt -Theme Powerlevel10k-Lean # angoster、JanDeDobbeleer
# > Set-Theme Powerlevel10k-Lean # angoster
~~~
# posh-git
可以為 PowerShell 提供 git 命令補全。 oh-my-posh 可以美化 prompt,提供各種主題。直接把兩個一起安上:
## oh-my-posh
oh-my-posh提供了 10 款 漂亮 的主題供我們選擇。
```
`Agnoster`,`Avit`,`Darkblood`,`Fish`,`Honukai`,`Paradox`,`PowerLine`,`robbyrussell`,`Sorin`,`tehrob`
```
# [PSReadLine](https://github.com/PowerShell/PSReadLine) 命令行提示記錄
PSReadLine 是 PowerShell 的官方模塊,為 PowerShell 提供了缺失的交互特性。例如像 zsh/fish 那樣的交互式的補全、語法高亮、emacs按鍵模式等等。有了 PSReadLIne 之后的 PowerShell 才終于像點樣了。
安裝([詳見官方項目README](https://github.com/PowerShell/PSReadLine)):
```powershell
> Install-Module -Name PSReadLine -AllowPrerelease -Force # PSReadLine
```
安裝之后,PSReadLine 的一些特性并不會自動啟用,可以在 PowerShell 的 profile 配置文件里自己按需配置。但是自己從頭搞畢竟很煩,直接白嫖官方提供的[配置樣例](https://github.com/PowerShell/PSReadLine/blob/master/PSReadLine/SamplePSReadLineProfile.ps1)就可以,已經非常好用了。
# [Starship](https://starship.rs/zh-CN/guide/) 美化顯示樣式
Starship?是一個用?Rust?編寫的開源項目,它可以幫助你建立一個精簡、快速、可定制的 shell 提示符;配置各種語言工程**prompt**的**icon**,文檔有完整的例子:
```
> scoop install starship
```
## 配置`starship`
創建這個文件夾并創建`startship.toml`
如果有這個`.config`這個文件夾,直接
```
> touch ~/.config/starship.toml
> notepad.exe ~/.config/starship.toml
```
`starship.toml`輸入如下內容:
```
[character]
symbol = "?"
[aws]
symbol = " "
[battery]
full_symbol = "?"
charging_symbol = "?"
discharging_symbol = "?"
[conda]
symbol = "? "
[docker]
symbol = "? "
[elixir]
symbol = " "
[elm]
symbol = " "
[git_branch]
symbol = "? "
[golang]
symbol = " "
[haskell]
symbol = " "
[hg_branch]
symbol = "? "
[java]
symbol = " "
[julia]
symbol = " "
[memory_usage]
symbol = "? "
[nix_shell]
symbol = "? "
[nodejs]
# symbol = " "
symbol="? "
[package]
symbol = "? "
[php]
symbol = " "
[python]
symbol = " "
[ruby]
symbol = " "
[rust]
symbol = "? "
```
具體配置看[官網](https://gitee.com/mirrors/starship),如果出現的小方框或者亂碼是字體缺失,那么需要安裝一種 [Nerd 字體](https://www.nerdfonts.com/) 并在您的終端啟用!
## 配置 Nerd Font 字體
1. 下載`FiraCode Nerd Font`字體 或其他自己喜歡的字體
打開 [nerdfonts](https://www.nerdfonts.com/font-downloads) 網站,滑到找到`FiraCode Nerd Font`下載解壓,全選&右鍵安裝
> 個人使用 [i-tu/Hasklig](https://hub.fastgit.org/i-tu/Hasklig/releases) 字體
1. 在`windows terminal`中配置字體:
```json
.....
// powershell 7
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"commandline": "C:/Program Files/PowerShell/7-preview/pwsh.exe -nologo",
"fontSize": 12,
// 字體配置
"fontFace": "FiraCode Nerd Font",
"historySize": 9001,
"padding": "5, 5, 20, 25",
"snapOnInput": true,
"colorScheme": "Andromeda",
"source": "Windows.Terminal.PowershellCore"
}
.....
```
# [colortool](https://github.com/microsoft/terminal/releases/tag/1708.14008) 顏色配置
主要是配置字體和配色方案。配色方案可以使用 `colortool`,或者在 [iTerm2-Color-Schemes](https://hub.fastgit.org/mbadolato/iTerm2-Color-Schemes) 這個項目中挑選。個人比較喜歡 Gruvbox Dark 配色。
```
> scoop install colortool
```
## 配置`colortool`
```powershell
> colortool -s # 查看配色方案
> colortool OneHalfDark.itermcolors # colortools 后面跟主題名字就行
```
在 Windows Terminal 配置文件中加入 Gruvbox Dark 配色方案:
~~~json
"schemes": [
{
"name": "Xee Gruvbox Dark",
"black": "#1e1e1e",
"red": "#be0f17",
"green": "#868715",
"yellow": "#cc881a",
"blue": "#377375",
"purple": "#a04b73",
"cyan": "#578e57",
"white": "#978771",
"brightBlack": "#7f7061",
"brightRed": "#f73028",
"brightGreen": "#aab01e",
"brightYellow": "#f7b125",
"brightBlue": "#719586",
"brightPurple": "#c77089",
"brightCyan": "#7db669",
"brightWhite": "#e6d4a3",
"background": "#1e1e1e",
"foreground": "#e6d4a3"
}
]
~~~
## 其他主題工具
[atomcorp/themes: Themes for Windows Terminal](https://github.com/atomcorp/themes) 直接由主題網站瀏覽順眼的配色,再一鍵復制并貼入Windows Terminal的設定檔,超級簡單!
* 配色主題展示:[iTerm2 Color Schemes](https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/windowsterminal)
# 參考
> [Windows Terminal 終極美化](https://www.chuchur.com/article/windows-terminal-beautify)