Windows Terminal 美化
前言
windows11 作为我当下最常用的操作系统,很多时候需要在 windows11 上进行娱乐、开发等工作。
为了优化开发体验,对 windows terminal 做一些优化和美化,下面是详细步骤。
1 powershell7
1.1 简介
PowerShell 7 是专为云、本地和混合环境设计的,它包含增强功能和新功能。
与 Windows PowerShell 并行安装和运行 提升了与现有 Windows PowerShell 模块的兼容性 新语言功能(如三元运算符和 ForEach-Object -Parallel) 提高了性能 基于 SSH 的远程处理 跨平台互操作性 支持 Docker 容器
1.2 安装
直接使用 winget 安装:
winget install Microsoft.PowerShell -s winget
。
安装完后,更改配置使 windows terminal 默认启动 powershell7,光标形状为空心框。
2 starship
2.1 简介
最开始用的是 oh-my-posh,它是 PowerShell 主题管理工具,但是,试用过后觉得它拖累了 pwsh的速度,平均都每次启动要 2600 ~ 3600 ms 左右,实在忍不了,因为它为了跨平台采用 go 语言实现。
所以我选择了使用 rust 语言实现的 starship,每次启动最多不超过 500 ms,体验非常好。
2.2 安装
1. 安装字体 NerdFont
这里我选择了 FiraCodeNerdFont。
安装后,修改 pwsh 字体为:FiraCodeNerdFont。
2. 安装 Starship
使用包管理器 winget 安装:
winget install starship
。
3. 简单配置
修改配置文件。
可以在 PowerShell 通过 $PROFILE
变量来查询文件的位置。
通常文件路径是 ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
或 ~/.config/powershell/Microsoft.PowerShell_profile.ps1
。
>notepad $PROFILE
打开文件后添加以下内容:
Invoke-Expression (&starship init powershell)
2.3 个性化配置
1. 创建配置文件
在家目录下创建 .config/starship.toml
文件。
配置可以参考一份仿 ys 配置:
# Use custom format
[username]
style_user = "white bold"
style_root = "black bold"
format = "[$user]($style) "
disabled = false
show_always = true
[directory]
truncation_length = 8
truncation_symbol = "…/"
[hostname]
ssh_only = false
format = "on [$hostname](bold red) "
trim_at = ".companyname.com"
disabled = false
[status]
style = "bg:blue"
symbol = "🔴"
format = '[\[$symbol $common_meaning$signal_name$maybe_int\]]($style) '
map_symbol = true
disabled = false
[time]
disabled = false
format = '[\[ $time \]]($style) '
time_format = "%T"
utc_time_offset = "+8"
效果:
我参考了很多配置后魔改的配置是:
#[line_break]
#disable = true
#add_newline = false
[line_break]
disabled = true
[username]
style_user = "white bold"
style_root = "black bold"
format = "[shachi]($style) "
disabled = false
show_always = true
[status]
style = "bg:#bd93f9"
symbol = "❌"
format = '[\[$symbol $common_meaning$signal_name$maybe_int\]]($style) '
map_symbol = true
disabled = false
[time]
disabled = false
format = '[\[ $time \]]($style) '
time_format = "%T"
utc_time_offset = "+8"
[c]
commands = [['','']]
symbol = " "
[directory.substitutions]
"Documents" = ""
"Downloads" = ""
"Music" = ""
"Pictures" = ""
[aws]
symbol = " "
[buf]
symbol = " "
[conda]
symbol = " "
[dart]
symbol = " "
[directory]
read_only = " "
truncation_length = 8
truncation_symbol = "…/"
[docker_context]
symbol = " "
[elixir]
symbol = " "
[elm]
symbol = " "
[fossil_branch]
symbol = " "
[git_branch]
symbol = " "
[golang]
symbol = " "
[guix_shell]
symbol = " "
[haskell]
symbol = " "
[haxe]
symbol = "⌘ "
[hg_branch]
symbol = " "
[hostname]
ssh_symbol = " "
ssh_only = false
#format = "@ [$hostname]($style)"
format = "@ lenovo in ($style)"
trim_at = "-"
style = "bold dimmed white"
disabled = false
[java]
symbol = " "
[julia]
symbol = " "
[lua]
symbol = " "
[memory_usage]
symbol = " "
[meson]
symbol = " "
[nim]
symbol = " "
[nix_shell]
symbol = " "
[nodejs]
symbol = " "
[os.symbols]
Alpaquita = " "
Alpine = " "
Amazon = " "
Android = " "
Arch = " "
Artix = " "
CentOS = " "
Debian = " "
DragonFly = " "
Emscripten = " "
EndeavourOS = " "
Fedora = " "
FreeBSD = " "
Garuda = " "
Gentoo = " "
HardenedBSD = " "
Illumos = " "
Linux = " "
Mabox = " "
Macos = " "
Manjaro = " "
Mariner = " "
MidnightBSD = " "
Mint = " "
NetBSD = " "
NixOS = " "
OpenBSD = " "
openSUSE = " "
OracleLinux = " "
Pop = " "
Raspbian = " "
Redhat = " "
RedHatEnterprise = " "
Redox = " "
Solus = " "
SUSE = " "
Ubuntu = " "
Unknown = " "
Windows = " "
[package]
symbol = " "
[pijul_channel]
symbol = "🪺 "
[python]
symbol = " "
[rlang]
symbol = " "
[ruby]
symbol = " "
[rust]
symbol = " "
[scala]
symbol = " "
[spack]
symbol = "🅢 "
效果:
3 其他
3.1 安装 gsudo
这样就可以在 windows 上像在 linux 中一样方便地使用 sudo
获取管理员权限了。
winget install gsudo --source winget
3.2 在包含 C 语言文件的路径下打开 powershell 会出现警告
[WARN] - (starship::utils): Unable to decode stdout: FromUtf8Error
……
error: Utf8Error { valid_up_to: 77, error_len: Some(1) } }
如图:
后来分析,应该是 starship 没办法正确解析 gcc --version
输出的版本数据。
查阅 starship文档 后发现
C 的配置项里:
有个 commands
,默认值为 [ [ 'cc', '--version' ], [ 'gcc', '--version' ], [ 'clang', '--version' ] ]
,用来检测编译器的版本。
可能是因为我用的是 tdmgcc?
$ gcc --version
gcc.exe (tdm64-1) 10.3.0
Copyright (c) 2020 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
解决办法很简单,删除默认值即可。
[c]
commands = [['','']]
参考
留言或评论请使用 Github Issues。