个人喜欢使用终端命令行,但默认的终端有点过于枯燥且不美观。
安装
- oh-my-posh 用于美化终端
- starship 用于美化终端
- PSReadLine 用于终端输入提示
- posh-git 用于获取当前项目的 git 信息
- clink 用于 CMD 终端
- Terminal-Icons 用于终端文件图标
注意
oh-my-posh
和 starship
是不同的终端美化工具,两者只需选择一个,当然你也可以都安装,后期通过配置灵活切换。我这里选择的是 starship
。
Nerd Font
字体下载: Nerd Fonts,推荐 Hack Nerd Font
字体。
Windows Terminal
主题下载: Windows Terminal Themes,我这里使用的主题是 Flatland
,但修改了 "brightBlack": "#686865"
。
json
{
"background": "#1D1F21",
"black": "#1D1D19",
"blue": "#5096BE",
"brightBlack": "#686865",
"brightBlue": "#61B9D0",
"brightCyan": "#D63865",
"brightGreen": "#A7D42C",
"brightPurple": "#695ABC",
"brightRed": "#D22A24",
"brightWhite": "#FFFFFF",
"brightYellow": "#FF8949",
"cursorColor": "#708284",
"cyan": "#D63865",
"foreground": "#B8DBEF",
"green": "#9FD364",
"name": "Flatland",
"purple": "#695ABC",
"red": "#F18339",
"selectionBackground": "#2B2A24",
"white": "#FFFFFF",
"yellow": "#F4EF6D"
}
编辑 PowerShell
配置文件:
sh
notepad $PROFILE # 或者使用你喜欢的编辑器 `code $PROFILE`
sh
# oh-my-posh3 设置主题
#Set-PoshPrompt -Theme negligible
# 导入 Terminal-Icons 模块
Import-Module -Name Terminal-Icons
# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History
# 设置 Tab 键补全
Set-PSReadlineKeyHandler -Key Tab -Function Complete
# 设置 Ctrl+d 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete
# 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
starship.toml
配置:
toml
# 根据 schema 提供自动补全
"$schema" = 'https://starship.rs/config-schema.json'
# 在提示符之间插入空行
add_newline = true
format = '''$time$all'''
right_format = '''$battery'''
# 替换提示符
[character]
success_symbol = '[❯](bold green)'
error_symbol = '[❯](bold red)'
[battery]
full_symbol = '[ ](bold green)'
charging_symbol = '[ ](bold green)'
discharging_symbol = '[ ](bold yellow)'
# 电池电量低于 10%
[[battery.display]]
threshold = 10
style = 'bold red'
# 电池电量低于 30%
[[battery.display]]
threshold = 30
style = 'bold yellow'
# 电池电量低于 100%
# [[battery.display]]
# threshold = 100
# style = 'bold green'
# 时间组件展示
[time]
disabled = false
format = '[ $time ](bold blue)'
# 禁用 'package' 组件,将其隐藏
[package]
disabled = true
以上配置设置完你应该能得到一个十分美观的 Windows Terminal
,但你可能还需要进行如下配置:
- 设置 PowerShell 执行策略: Set-ExecutionpPolicy
PowerShell 终端加载慢
管理员方式运行:
ps
$env:PATH = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
[AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object {
$path = $_.Location
if ($path) {
$name = Split-Path $path -Leaf
Write-Host -ForegroundColor Yellow "`r`nRunning ngen.exe on '$name'"
ngen.exe install $path /nologo
}
}