Windows Terminal 终端配置

Terminal配置

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
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions": [],
"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{9ae8d8bf-8c74-4504-9c00-51d369f92d11}",
"initialCols": 115,
"initialRows": 30,
"keybindings": [
{
"id": "Terminal.CopyToClipboard",
"keys": "ctrl+c"
},
{
"id": "Terminal.PasteFromClipboard",
"keys": "ctrl+v"
},
{
"id": "Terminal.DuplicatePaneAuto",
"keys": "alt+shift+d"
}
],
"newTabMenu": [
{
"type": "remainingProfiles"
}
],
"profiles": {
"defaults": {
"font": {
"face": "Maple Mono NF CN"
},
"opacity": 75,
"useAcrylic": true
},
"list": [
{
"commandline": "%SystemRoot%\\System32\\cmd.exe",
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"hidden": false,
"name": "\u547d\u4ee4\u63d0\u793a\u7b26",
"startingDirectory": null
},
{
"altGrAliasing": true,
"antialiasingMode": "grayscale",
"closeOnExit": "automatic",
"colorScheme": "Campbell",
"commandline": "D:\\App\\PowerShell\\7\\pwsh.exe",
"cursorShape": "bar",
"font": {
"face": "Maple Mono NF CN",
"size": 12
},
"guid": "{9ae8d8bf-8c74-4504-9c00-51d369f92d11}",
"hidden": false,
"historySize": 9001,
"icon": "D:\\App\\PowerShell\\7\\assets\\Powershell_av_colors.ico",
"name": "PowerShell",
"padding": "8, 8, 8, 8",
"snapOnInput": true
},
{
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"hidden": false,
"name": "Windows PowerShell"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
"hidden": false,
"name": "Git Bash",
"source": "Git",
"startingDirectory": null
},
{
"commandline": "cmd.exe /k \"D:\\Documents\\Terminal\\start_conda.bat",
"guid": "{8cfc2a3d-a71d-5e12-a62a-05c2ad7340b7}",
"hidden": false,
"icon": "D:\\App\\Anaconda3\\Menu\\anaconda_prompt.ico",
"name": "Anaconda CMD"
},
{
"guid": "{59d2bd70-f9a6-5353-baf7-81a6b2ad87d7}",
"hidden": false,
"name": "Python Command Prompt",
"source": "ArcGIS"
},
{
"guid": "{5e06c8d3-9340-56cb-8a07-8917603c0f0f}",
"hidden": false,
"name": "Developer Command Prompt for VS 18",
"source": "Windows.Terminal.VisualStudio"
},
{
"guid": "{6a558363-9153-5e07-b499-d6550e96df0b}",
"hidden": false,
"name": "Developer PowerShell for VS 18",
"source": "Windows.Terminal.VisualStudio"
}
]
},
"schemes": [],
"themes": []
}

全部配置

D:\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
# 自动补全历史命令,逐字补全
Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource History

# 修改Tab补全为bash风格
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

# 全新的主题
oh-my-posh init pwsh --config "D:\Documents\Terminal\distrous-windows-11.omp.json" | Invoke-Expression

# 命令提示
# Write-Output "【环境】
# 初始化:conda init powershell
# 关闭环境自动激活:conda config --set auto_activate_base false
# 列举所有环境:conda env list
# 进入某个环境(比如local_nmt):conda activate local_nmt
# 退出当前环境:conda deactivate
# 创建新的环境(比如mp1):conda create --name mp1
# 删除某个环境(比如tf1.12):conda remove --name tf1.12 --all
# 【包】
# 列举当前活跃环境下的所有包:conda list
# 列举指定环境下的所有包:conda list -n your_env_name
# 在当前环境下安装某个包:conda install package_name
# 在指定环境下安装某个包:conda instll -n env_name package_name"

D:\Documents\PowerShell\profile.ps1

如果加载慢就将下面的全部注释掉

1
2
3
4
5
6
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
# If (Test-Path "D:\App\Anaconda3\Scripts\conda.exe") {
# (& "D:\App\Anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
# }
#endregion

Anaconda Python 配置

D:\Documents\Terminal\start_conda.bat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@echo off
call D:\App\Anaconda3\Scripts\activate.bat
chcp 65001
echo ============================环境=============================
echo 列举所有环境:conda env list
echo 进入某个环境(比如local_nmt):conda activate local_nmt
echo 退出当前环境:conda deactivate
echo 创建新的环境(比如mp1):conda create --name mp1
echo 删除某个环境(比如tf1.12):conda remove --name tf1.12 --all
echo =============================包==============================
echo 列举当前活跃环境下的所有包:conda list
echo 列举指定环境下的所有包:conda list -n your_env_name
echo 在当前环境下安装某个包:conda install package_name
echo 在指定环境下安装某个包:conda instll -n env_name package_name
cmd /k

OhMyPosh主题

D:\Documents\Terminal\distrous-windows-11.omp.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"console_title_template": "{{ if .Root }}root @ {{ end }}{{ .Shell }} in {{ .Folder }}",
"blocks": [
// 第一行左
{
"alignment": "left",
"segments": [
{
"background": "#0077D4",
"foreground": "#FFFFFF",
"leading_diamond": "",
"style": "diamond",
"template": "<b>  Win </b>",
"type": "os"
},
{
"background": "#744CA9",
"foreground": "#FFFFFF",
"powerline_symbol": "",
"style": "powerline",
"template": "<b> \uf09c root </b>",
"type": "root"
},
{
"background": "#6B68D6",
"foreground": "#FFFFFF",
"powerline_symbol": "",
"style": "powerline",
"template": "<b> \uf489 {{ .Name }} </b>",
"type": "shell"
},
{
"type": "java",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#ffffff",
"background": "#4063D8",
"template": "  {{ .Full }}"
},
{
"type": "python",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#ffd43b",
"background": "#306998",
"template": "  {{ .Full }} "
},
{
"type": "go",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#ffffff",
"background": "#7FD5EA",
"template": "  {{ .Full }} "
},
{
"type": "rust",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#193549",
"background": "#99908a",
"template": "  {{ .Full }} "
},
{
"type": "node",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#ffffff",
"background": "#6CA35E",
"template": "  {{ .Full }} "
},
{
"type": "php",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#ffffff",
"background": "#4063D8",
"template": "  {{ .Full }} "
},
{
"type": "r",
"style": "powerline",
"powerline_symbol": "",
"foreground": "blue",
"background": "lightWhite",
"template": "  {{ .Full }} "
},
{
"type": "npm",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#193549",
"background": "#ffeb3b",
"template": "  {{ .Full }} "
},
{
"type": "pnpm",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#000000",
"background": "#F9AD00",
"template": "  {{ .Full }} "
},
{
"type": "react",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#81a1c1",
"template": "  {{ .Full }} "
},
{
"type": "tauri",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#000000",
"background": "#1976d2",
"template": "  {{ .Full }} "
},
{
"type": "yarn",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#FFFFFF",
"background": "#2E2A65",
"template": "  {{ .Full }} "
},
{
"type": "git",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#193549",
"background": "#ffeb3b",
"background_templates": [
"{{ if or (.Working.Changed) (.Staging.Changed) }}#FFEB3B{{ end }}",
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#FFCC80{{ end }}",
"{{ if gt .Ahead 0 }}#B388FF{{ end }}",
"{{ if gt .Behind 0 }}#B388FB{{ end }}"
],
"template": " {{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }}  {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }}  {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }}  {{ .StashCount }}{{ end }}",
"options": {
"fetch_status": true,
"fetch_upstream_icon": true,
"untracked_modes": {
"/Users/user/Projects/oh-my-posh/": "no"
},
"source": "cli",
"mapped_branches": {
"feat/*": "🚀 ",
"bug/*": "🐛 "
}
}
}
],
"type": "prompt"
},
// 第一行右
{
"alignment": "right",
"segments": [
{
"background": "#03DE6C",
"background_templates": [
"{{ if gt .Code 0 }}#E44141{{ end }}"
],
"foreground": "#000000",
"foreground_templates": [
"{{ if gt .Code 0 }}#FFFFFF{{ end }}"
],
"leading_diamond": "\ue0b2",
"options": {
"always_enabled": true
},
"style": "diamond",
"template": "{{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }}",
"type": "status",
"trailing_diamond": "\ue0b0"
},
{
"background": "#0077D4",
"foreground": "#FFFFFF",
"options": {
"style": "roundrock",
"threshold": 0
},
"style": "diamond",
"template": " \uf252 {{ .FormattedMs }}",
"trailing_diamond": "\ue0b0",
"type": "executiontime"
}
],
"type": "prompt"
},
// 第二行左
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "#fff",
"style": "plain",
"template": "\u256d\u2500",
"type": "text"
},
{
"foreground": "#ff6040",
"options": {
"time_format": " \uf073 2006/01/02 \uf104 January \uf142 Wednesday \uf105"
},
"style": "plain",
"template": "{{ .CurrentDate | date .Format }}",
"type": "time"
}
],
"type": "prompt"
},
// 第二行右
{
"alignment": "right",
"segments": [
{
"type": "time",
"style": "plain",
"foreground": "#ff8c00",
"options": {
"time_format": "15:04:05"
}
}
],
"type": "prompt"
},
// 第三行左
{
"alignment": "left",
"newline": true,
"type": "prompt",
"segments": [
{
"foreground": "#fff",
"style": "plain",
"template": "\u2502",
"type": "text"
},
{
"type": "session",
"style": "plain",
"foreground": "#0095ff",
"template": " \uf007 {{ if .SSHSession }} {{ end }}{{ .UserName }} |  {{ .HostName }}"
}
]
},
// 第三行右
{
"alignment": "right",
"segments": [
{
"type": "winreg",
"style": "plain",
"foreground": "#0095ff",
"trailing_diamond": "",
"template": "  {{ .Value }}",
"options": {
"path": "HKLM\\software\\microsoft\\windows nt\\currentversion\\buildlab",
"fallback": "unknown"
}
}
],
"type": "prompt"
},
// 第四行左
{
"alignment": "left",
"newline": true,
"type": "prompt",
"segments": [
{
"foreground": "#fff",
"style": "plain",
"template": "\u2502",
"type": "text"
},
{
"options": {
"folder_icon": " \uf07c ",
"folder_separator_icon": "<#fff>\\</>",
"home_icon": "\uf015",
"style": "agnoster_short",
"max_depth": 4,
"right_format": "<u><b>%s</b></u>",
"mapped_locations": {
"~/Videos": "\uf015 <#fff>\uf061</> \uf03d",
"~/Desktop": "\uf015 <#fff>\uf061</> \uf108",
"~/Documents": "\uf015 <#fff>\uf061</> \udb80\ude19",
"~/Downloads": "\uf015 <#fff>\uf061</> \uf019",
"~/Pictures/": "\uf015 <#fff>\uf061</> \uf03e",
"~/Music": "\uf015 <#fff>\uf061</> \uf001"
}
},
"style": "plain",
"template": " <#00CC69>{{ if not .Writable }}<#DA3B00>\uf09c {{ end }}{{ if .RootDir }}\ue216{{ else }}{{ .Path }}{{ end }}</> ",
"type": "path"
}
]
},
// 第四行右
{
"alignment": "right",
"segments": [
{
"type": "project",
"style": "plain",
"foreground": "#e1d035",
"template": " {{ if .Error }}{{ .Error }}{{ else }}{{ if .Version }} {{.Version}}{{ end }} {{ if .Name }}{{ .Name }}{{ end }}{{ end }} "
}
],
"type": "prompt"
},
// 第五行左
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "#fff",
"style": "plain",
"template": "\u2570\u2500",
"type": "text"
},
{
"foreground": "#fff",
"options": {
"always_enabled": true
},
"style": "plain",
"template": "\u276f ",
"type": "status"
}
],
"type": "prompt"
}
],
"osc99": true,
"secondary_prompt": {
"background": "transparent",
"foreground": "#fff",
"template": "\u2570\u2500\u276f "
},
"version": 3
}

代理设置

PowerShell 设置代理

1
notepad $PROFILE

使用记事本打开一个文件,在文件中加入上面设置代理的命令,保存关闭即可。

上面的配置文件在 此电脑\文档\WindowsPowerShell 下,文件名为:Microsoft.PowerShell_profile.ps1, 这个文件的内容会在 PowerShell 的每次运行时使用。(注意不要修改文件位置,除非你明白这样操作的目的)

Git 设置代理

不得不说,为终端设置代理主要是为 git 设置全局代理,这里给出单独设置的方法。

1
2
git config --global https.proxy http://127.0.0.1:7890
git config --global https.proxy https://127.0.0.1:7890

这里给出取消设置代理的方法,防止端口需要切换。

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

查看代理

1
2
git config --global --get http.proxy
git config --global --get https.proxy