WindowsTerminal环境搭建

1.安装 Windows Terminal

​ 从 Microsoft Store 搜索下载

2.安装新款 Powershell Core

​ 从Powershell Core选择release版本下载

3.安装 Powershell 插件

​ 打开刚装好的新版 powershell,,运行以下命令:

1
2
3
4
5
6
7
8
# 1. 安装 PSReadline 包,该插件可以让命令行很好用,类似 zsh
Install-Module -Name PSReadLine -Scope CurrentUser

# 2. 安装 posh-git 包,让你的 git 更好用
Install-Module posh-git -Scope CurrentUser

# 3. 安装 oh-my-posh 包,让你的命令行更酷炫、优雅
Install-Module oh-my-posh -Scope CurrentUser

安装过程可能有点慢,好像卡住了一样,但是请耐心等待几分钟。等不及的同学自行搜索科学方法访问 GitHub.

安装时系统会提问是否继续,不用管它直接输入 A 并回车即可。

4. 配置 Windows Terminal

核心步骤:配置setting.json

需要下载字体,有些字体不匹配会出现乱码。

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
// 默认的配置就是我们的新 powershell(重要!!!)
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",

{
// 键标记
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"name": "PowerShell Core 7.1.0.5",
// 行为
"closeOnExit": true,
"commandline": "C:/Program Files/PowerShell/7-preview/pwsh.exe -nologo",
"hidden": false,
"historySize": 9001,
"snapOnInput": true,
"startingDirectory": ".",
// 外观
"icon": "D:/Users/newton/Documents/Softwares/software_windows/develop/shell/pwsh.ico",
"acrylicOpacity": 0.5,
"cursorColor": "#FFFFFF",
"cursorShape": "bar",
"fontFace": "JetBrains Mono",
"fontSize": 11,
"padding": "5, 5, 20, 25",
"useAcrylic": false,
// 颜色主题
"colorScheme": "Homebrew"
},

同时附上 Homebrew 配色,该配色经过我改良。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"name": "Homebrew",
"black": "#000000",
"red": "#FC5275",
"green": "#00a600",
"yellow": "#999900",
"blue": "#6666e9",
"purple": "#b200b2",
"cyan": "#00a6b2",
"white": "#bfbfbf",
"brightBlack": "#666666",
"brightRed": "#e50000",
"brightGreen": "#00d900",
"brightYellow": "#e5e500",
"brightBlue": "#0000ff",
"brightPurple": "#e500e5",
"brightCyan": "#00e5e5",
"brightWhite": "#e5e5e5",
"background": "#283033",
"foreground": "#00ff00"
},

5.添加启动参数

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#------------------------------- Import Modules BEGIN -------------------------------
# 引入 posh-git
Import-Module posh-git

# 引入 oh-my-posh
Import-Module oh-my-posh

# 引入 ps-read-line
Import-Module PSReadLine

# 设置 PowerShell 主题
# Set-PoshPrompt ys
Set-PoshPrompt paradox
#------------------------------- Import Modules END -------------------------------





#------------------------------- Set Hot-keys BEGIN -------------------------------
# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History

# 每次回溯输入历史,光标定位于输入内容末尾
Set-PSReadLineOption -HistorySearchCursorMovesToEnd

# 设置 Tab 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete

# 设置 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 Hot-keys END -------------------------------





#------------------------------- Functions BEGIN -------------------------------
# Python 直接执行
$env:PATHEXT += ";.py"

# 更新系统组件
function Update-Packages {
# update pip
Write-Host "Step 1: 更新 pip" -ForegroundColor Magenta -BackgroundColor Cyan
$a = pip list --outdated
$num_package = $a.Length - 2
for ($i = 0; $i -lt $num_package; $i++) {
$tmp = ($a[2 + $i].Split(" "))[0]
pip install -U $tmp
}

# update TeX Live
$CurrentYear = Get-Date -Format yyyy
Write-Host "Step 2: 更新 TeX Live" $CurrentYear -ForegroundColor Magenta -BackgroundColor Cyan
tlmgr update --self
tlmgr update --all

# update Chocolotey
Write-Host "Step 3: 更新 Chocolatey" -ForegroundColor Magenta -BackgroundColor Cyan
choco outdated
}
#------------------------------- Functions END -------------------------------





#------------------------------- Set Alias BEGIN -------------------------------
# 1. 编译函数 make
function MakeThings {
nmake.exe $args -nologo
}
Set-Alias -Name make -Value MakeThings

# 2. 更新系统 os-update
Set-Alias -Name os-update -Value Update-Packages

# 3. 查看目录 ls & ll
function ListDirectory {
(Get-ChildItem).Name
Write-Host("")
}
Set-Alias -Name ls -Value ListDirectory
Set-Alias -Name ll -Value Get-ChildItem

# 4. 打开当前工作目录
function OpenCurrentFolder {
param
(
# 输入要打开的路径
# 用法示例:open C:\
# 默认路径:当前工作文件夹
$Path = '.'
)
Invoke-Item $Path
}
Set-Alias -Name open -Value OpenCurrentFolder
#------------------------------- Set Alias END -------------------------------





#------------------------------- Set Network BEGIN -------------------------------
# 1. 获取所有 Network Interface
function Get-AllNic {
Get-NetAdapter | Sort-Object -Property MacAddress
}
Set-Alias -Name getnic -Value Get-AllNic

# 2. 获取 IPv4 关键路由
function Get-IPv4Routes {
Get-NetRoute -AddressFamily IPv4 | Where-Object -FilterScript {$_.NextHop -ne '0.0.0.0'}
}
Set-Alias -Name getip -Value Get-IPv4Routes

# 3. 获取 IPv6 关键路由
function Get-IPv6Routes {
Get-NetRoute -AddressFamily IPv6 | Where-Object -FilterScript {$_.NextHop -ne '::'}
}
Set-Alias -Name getip6 -Value Get-IPv6Routes
#------------------------------- Set Network END -------------------------------
作者

Cindy

发布于

2022-03-03

许可协议

CC BY-NC-SA 4.0

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×