Windows Termianl 美化配置指北

Windows Terminal 介绍

官方github地址:https://github.com/microsoft/terminal

少数派:https://sspai.com/post/59380

新晋 Windows 终端模拟器:Windows Terminal,自发布以来就备受开发者的喜爱,并与 WSL 一起,让不少先前非 Linux 不用的开发者朋友们向 Windows 倾斜。Windows Terminal 不仅开源免费,还拥有现代化的界面、完整的字体字符渲染机制(包括 Emoji)、GPU 加速和 Fluent 设计风格。这些都让 Windows Terminal 成为 Windows 平台最先进的终端模拟器,力压一众第三方终端以及 Windows 自带的默认终端。

  • 支持WSL2,SSH,Powershell,cmd和其他命令行
  • 多个选项卡和拆分窗格
  • 搜索框
  • 自定义键绑定
  • GPU加速文字渲染
  • 美观的新字体Cascadia Code
  • 资源使用率低(每个选项卡通常10MB)
  • 自动更新(如果使用Microsoft Store)

Windows Terminal 2.0 开发路线图:https://github.com/microsoft/terminal/blob/main/doc/terminal-v2-roadmap.md

安装 Windows Terminal

在官方 README 中,安装Windows Terminal有如下方法:

  • Microsoft Store(推荐)

  • Github

    https://github.com/microsoft/terminal/releases

    1
    Add-AppxPackage Microsoft.WindowsTerminal_<versionNumber>.msixbundle
  • winget

    1
    winget install --id=Microsoft.WindowsTerminal -e
  • Chocolatey

    1
    choco install microsoft-windows-terminal
  • Scoop

    1
    2
    scoop bucket add extras
    scoop install windows-terminal

这里使用Microsoft Store进行安装,简单直接,还能自动更新【doge】

image-20220207200021516

Windows Terminal 配置

官方配置文档:https://docs.microsoft.com/zh-cn/windows/terminal/customize-settings/profile-general

1
2
ctrl + ,进入设置页面
目前版本已经实现大部分内容的可视化设置。。。
1
进入设置界面后,左下角点击设置按钮,即可编辑setting.json文件

窗口设置

通过坐标 “initialPosition”参数 控制窗口位置。

1
2
3
"initialCols": 97,
"initialPosition": "480,250",
"initialRows": 27

颜色配置

在线预览颜色配置:https://windowsterminalthemes.dev/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// one,自用配色,修改自one of hack
{
"background": "#001B26",
"black": "#282C34",
"blue": "#61AFEF",
"brightBlack": "#5A6374",
"brightBlue": "#61AFEF",
"brightCyan": "#56B6C2",
"brightGreen": "#98C379",
"brightPurple": "#C678DD",
"brightRed": "#E06C75",
"brightWhite": "#DCDFE4",
"brightYellow": "#E5C07B",
"cursorColor": "#FFFFFF",
"cyan": "#56B6C2",
"foreground": "#DCDFE4",
"green": "#98C379",
"name": "One",
"purple": "#C678DD",
"red": "#E06C75",
"selectionBackground": "#FFFFFF",
"white": "#DCDFE4",
"yellow": "#E5C07B"
}

Profile配置

已实现可视化配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 个人使用配置
{
"acrylicOpacity": 0.6,
"backgroundImage": null,
"backgroundImageOpacity": 0.0,
"bellStyle": [
"window",
"taskbar"
],
"closeOnExit": "graceful",
"colorScheme": "One",
"commandline": "D:/PowerShell/7/pwsh.exe -nologo",
"cursorColor": "#AEAFAD",
"cursorShape": "filledBox",
"font": {
"face": "CaskaydiaCove NF",
"size": 10
},
"guid": "{xxxx-xxxx-xxx-xxx-xxx-xxxx-xxxx}",
"hidden": false,
"historySize": 9001,
"icon": "D:\\PowerShell\\7\\assets\\StoreLogo.png",
"name": "PowerShell",
"padding": "5",
"snapOnInput": true,
"startingDirectory": "%USERPROFILE%/Desktop",
"suppressApplicationTitle": true,
"useAcrylic": true
}

字体配置

字体下载:https://www.nerdfonts.com/font-downloads

1
2
Caskaydia Cove Nerd Font
Hack Nerd Font

PowerShell 配置

1
2
编辑 profile 文件
code $PROFILE

PSFzf

终端下的文件查找工具

1
Install-Module -Name PSReadLine  -Scope CurrentUser
1
2
3
# PSFzf
Import-Module -Name PSFzf
Set-PSFzfOption -PSReadlineChordProvider 'Ctrl+f' -PSReadlineChordReverseHistory 'Ctrl+r'

PSReadLine

历史命令提示

1
Install-Module -Name PSReadLine  -Scope CurrentUser

PS:如果powershell的版本大于等于6,将自动包含最新的PSReadLine,不需要再单独安装

1
$PSVersionTable # 查看powershell版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Import-Module
Import-Module PSReadLine
# # PSReadLine Option
# Set-PSReadLineOption -EditMode Emacs
# Set-PSReadLineOption -BellStyle None
Set-PSReadLineOption -PredictionSource History
# Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
# 设置 Tab 键补全
# Set-PSReadlineKeyHandler -Key Tab -Function Complete
# # 设置 Ctrl+d 为退出 PowerShell
# # Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit
# # 设置 Ctrl+z 为撤销
# Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
# # 设置向上键为后向搜索历史记录
# Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
# # 设置向下键为前向搜索历史纪录
# Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Set-PSReadLineOption -Colors @{
Command = "#e5c07b"
Number = "#cdd4d4"
Member = "#e06c75"
Operator = "#e06c75"
Type = "#78b6e9"
Variable = "#78b6e9"
Parameter = "#e06c75"
ContinuationPrompt = "#e06c75"
Default = "#cdd4d4"
Emphasis = "#e06c75"
Selection = "#cdd4d4"
Comment = "#cdd4d4"
Keyword = "#e06c75"
String = "#78b6e9"
InlinePrediction = "#9f9193"
}

zsh-Autosuggestion除了可以使用键补全全部外,还可以使用ctrl + →选择下一个单词。

1
2
3
# powershell-PSReadLine实现方式

Set-PSReadLineKeyHandler -Chord "Ctrl+RightArrow" -Function ForwardWord

ZLocation - 目录跳转

https://github.com/vors/ZLocation

类似于linux下的autojump

1
Install-Module ZLocation -Scope CurrentUser
1
Import-Module -Name z

usage:

1
z <dir_name>

Terminal-Icons

https://github.com/devblackops/Terminal-Icons

1
Install-Module -Name Terminal-Icons -Repository PSGallery
1
Import-Module -Name Terminal-Icons

image-20220207211444500

命令行流量代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function SetProxy {
Set-Item Env:all_proxy "socks5://127.0.0.1:10808"
}

function SetClashProxy {
Set-Item Env:all_proxy "socks5://127.0.0.1:7890"
}

function SetBurpProxy {
Set-Item Env:http_proxy "http://127.0.0.1:8080"
Set-Item Env:https_proxy "http://127.0.0.1:8080"
}

function UnSetBurpProxy {
Remove-Item Env:http_proxy
Remove-Item Env:https_proxy
}

function UnSetProxy {
Remove-Item Env:all_proxy
}

自定义提示符

starship

starship 安装

scoop install starship

1
2
# # -----------starship----------
Invoke-Expression (&starship init powershell)

pshazz

pshazz 安装

scoop install pshazz

1
2
# ---------pshazz----------
try { $null = gcm pshazz -ea stop; pshazz init 'default' } catch { }

oh-my-posh3

oh-my-posh3 配置

1
2
3
4
# 安装 posh-git 
Install-Module posh-git -Scope CurrentUser
# 安装 oh-my-posh
Install-Module oh-my-posh -Scope CurrentUser
1
2
# scoop安装方式
scoop install oh-my-posh3

自定义

1
2
3
4
5
6
7
8
# ----------command----------- 
function prompt
{
#Write-Host("$pwd>")
# "syyu@win " + "$pwd ~ `n $ "
" syyu@win " + "$pwd `n $ "
}

winfetch

一款花里胡哨的基本信息查看工具,类似的有 neofetch,screenfetch

1
scoop install winfetch

Scoop

scoop安装

1
2
3
4
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

# or shorter
iwr -useb get.scoop.sh | iex

Note: if you get an error you might need to change the execution policy (i.e. enable Powershell) with

1
Set-ExecutionPolicy RemoteSigned -scope CurrentUser

scoop Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Usage: scoop <command> [<args>]

Some useful commands are:

alias Manage scoop aliases
bucket Manage Scoop buckets
cache Show or clear the download cache
cat Show content of specified manifest.
checkup Check for potential problems
cleanup Cleanup apps by removing old versions
config Get or set configuration values
create Create a custom app manifest
depends List dependencies for an app
export Exports (an importable) list of installed apps
help Show help for a command
hold Hold an app to disable updates
home Opens the app homepage
info Display information about an app
install Install apps
list List installed apps
prefix Returns the path to the specified app
reset Reset an app to resolve conflicts
search Search available apps
status Show status and check for new app versions
unhold Unhold an app to enable updates
uninstall Uninstall an app
update Update apps, or Scoop itself
virustotal Look for app's hash on virustotal.com
which Locate a shim/executable (similar to 'which' on Linux)

Type 'scoop help <command>' to get help for a specific command.

scoop配置指南

见另一篇博客

#TODO

常用快捷键

  • win + 反引号(`)

打开Quake模式

  • 配置专注模式(eg: Alt + P)

显示/隐藏标题栏,在Quake模式(win + 反引号)也可触发

  • 分屏操作

https://docs.microsoft.com/zh-cn/windows/terminal/panes

Alt + Shift + (+) 水平窗格

Alt + Shift + (-) 垂直窗格

and so on …

#TODO

配置文件

Windows Terminal

C:\Users\%USERNAME%\AppData\Local\Packages\Microsoft.WindowsTerminal_xxxxxxxxxxxxx\LocalState\settings.json

1
...

#TODO

PowerShell 7

C:\Users\%USERNAME%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# SetProxy
function SetProxy {
Set-Item Env:all_proxy "socks5://127.0.0.1:10808"
}
function SetClashProxy {
Set-Item Env:all_proxy "socks5://127.0.0.1:7890"
}
function SetBurpProxy {
Set-Item Env:http_proxy "http://127.0.0.1:8080"
Set-Item Env:https_proxy "http://127.0.0.1:8080"
}
function UnSetBurpProxy {
Remove-Item Env:http_proxy
Remove-Item Env:https_proxy
}
function UnSetProxy {
Remove-Item Env:all_proxy
}

# Import-Module
Import-Module PSReadLine
Import-Module -Name Terminal-Icons
Import-Module -Name z
# Import-Module -Name PSFzf

Set-PSReadLineOption -PredictionSource History
# Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
# 设置ctrl + 右键,逐字补全
Set-PSReadLineKeyHandler -Chord "Ctrl+RightArrow" -Function ForwardWord

Set-PSReadLineOption -Colors @{
Command = "#e5c07b"
Number = "#cdd4d4"
Member = "#e06c75"
Operator = "#e06c75"
Type = "#78b6e9"
Variable = "#78b6e9"
Parameter = "#e06c75"
ContinuationPrompt = "#e06c75"
Default = "#cdd4d4"
Emphasis = "#e06c75"
Selection = "#cdd4d4"
Comment = "#cdd4d4"
Keyword = "#e06c75"
String = "#78b6e9"
InlinePrediction = "#9f9193"
}

# PSFzf
# Set-PSFzfOption -PSReadlineChordProvider 'Ctrl+f' -PSReadlineChordReverseHistory 'Ctrl+r'

# # -----------starship----------
Invoke-Expression (&starship init powershell)


# ----------command-----------
# function prompt
# {
# #Write-Host("$pwd>")
# # "syyu@win " + "$pwd ~ `n $ "
# " syyu@win " + "$pwd `n $ "
# }

# ---------pshazz----------
# try { $null = gcm pshazz -ea stop; pshazz init 'default' } catch { }

PowerShell

C:\Users\%USERNAME%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

好了,大致的配置就结束了。

看一波效果图…

image-20220207212029891

还有一些配置和图片,下次一定,先建个#TODO ,哈哈哈哈

参考链接

https://docs.microsoft.com/zh-cn/windows/terminal/

https://juejin.cn/post/6984620463917891614

https://elfile4138.moe/2021/08/Windows-Terminal%E7%9A%84%E9%85%8D%E7%BD%AE/