0%

Windows Terminal配置 与 添加PowerShell Core

准备

配置 Windows Terminal

打开Settings,编辑settings.json,为 PowerShell Core 先生成一个GUID,比如用 Online GUID Generator

在 list 中添加一项,如下:

1
2
3
4
5
6
7
{
"guid": "{be8c6241-aafb-437f-8d7c-a7142adf7f54}",
"name": "PowerShell Core",
"commandline": "D:\\Program Files\\PowerShell\\7\\pwsh.exe",
"icon": "D:\\Program Files\\PowerShell\\7\\assets\\ps_black_32x32.ico",
"hidden": false
},

注意:更改 commandline,icon 路径为你的安装路径

添加 Windows Terminal 到右键菜单

创建txt文件,内容为下方,注意:icon图标地址,与 yiyun 用户名 需修改

修改文件名为 添加右键菜单.reg,双击运行即可

1
2
3
4
5
6
7
8
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows Terminal here"
"Icon"="F:\\Com\\tools\\WindowsTerminal\\terminal.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="C:\\Users\\yiyun\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

完整配置参考

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
// This file was initially generated by Windows Terminal 1.1.2021.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",

"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings

// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,

// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,

// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles": {
"defaults": {
// Put settings here that you want to apply to all profiles.
"acrylicOpacity": 0.9,
"colorScheme": "Dark+",
"fontFace": "DejaVu Sans Mono for Powerline",
"hidden": false,
"useAcrylic": false, //true,
"startingDirectory": "." // 起始目录为当前打开目录
// "backgroundImage": "F://Com//tools//WindowsTerminal//background.gif", // 图片地址
// "backgroundImageOpacity" : 0.15, // 透明度
// "backgroundImageStretchMode": "fill" // 填充模式
},
"list": [
{
"guid": "{be8c6241-aafb-437f-8d7c-a7142adf7f54}",
"name": "PowerShell Core",
"commandline": "D:\\Program Files\\PowerShell\\7\\pwsh.exe",
"icon": "D:\\Program Files\\PowerShell\\7\\assets\\ps_black_32x32.ico",
"hidden": false
},
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{4c18d1cd-6d8d-426a-be2f-a4b3152a32c4}",
"hidden": false,
"name": "Python 3.8.6rc1",
"commandline": "D:\\Program Files\\python38\\python.exe",
"icon": "D:\\Program Files\\python38\\DLLs\\pyc.ico"
},
{
"guid": "{1c4de342-38b7-51cf-b940-2309a097f589}",
"hidden": false,
"name": "Git Bash",
"commandline": "D:\\Program Files\\Git\\bin\\bash.exe",
"acrylicOpacity": 0, // 透明度
"closeOnExit": true, // 关闭的时候退出命令终端
"cursorColor": "#FFFFFF", // 光标颜色
"cursorShape": "bar", // 光标形状
"fontFace": "YaHei Consolas Hybrid", // 字体配置,选择你电脑上已安装的字体
"fontSize": 14, // 终端字体大小
"icon": "D:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico", // git的图标
"historySize": 9001, // 终端窗口记忆大小
"padding": "0, 0, 0, 0", // 边距
"snapOnInput": true,
"useAcrylic": false // 是否开启透明度
}
]
},

// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [
{
"name": "Japanesque",
"black": "#343935",
"red": "#cf3f61",
"green": "#7bb75b",
"yellow": "#e9b32a",
"blue": "#4c9ad4",
"purple": "#a57fc4",
"cyan": "#389aad",
"white": "#fafaf6",
"brightBlack": "#595b59",
"brightRed": "#d18fa6",
"brightGreen": "#767f2c",
"brightYellow": "#78592f",
"brightBlue": "#135979",
"brightPurple": "#604291",
"brightCyan": "#76bbca",
"brightWhite": "#b2b5ae",
"background": "#1e1e1e",
"foreground": "#f7f6ec"
},
{
"name": "Snazzy",
"black": "#000000",
"red": "#fc4346",
"green": "#50fb7c",
"yellow": "#f0fb8c",
"blue": "#49baff",
"purple": "#fc4cb4",
"cyan": "#8be9fe",
"white": "#ededec",
"brightBlack": "#555555",
"brightRed": "#fc4346",
"brightGreen": "#50fb7c",
"brightYellow": "#f0fb8c",
"brightBlue": "#49baff",
"brightPurple": "#fc4cb4",
"brightCyan": "#8be9fe",
"brightWhite": "#ededec",
"background": "#1e1f29",
"foreground": "#ebece6"
},
{
"name": "Dark+",
"black": "#000000",
"red": "#cd3131",
"green": "#0dbc79",
"yellow": "#e5e510",
"blue": "#2472c8",
"purple": "#bc3fbc",
"cyan": "#11a8cd",
"white": "#e5e5e5",
"brightBlack": "#666666",
"brightRed": "#f14c4c",
"brightGreen": "#23d18b",
"brightYellow": "#f5f543",
"brightBlue": "#3b8eea",
"brightPurple": "#d670d6",
"brightCyan": "#29b8db",
"brightWhite": "#e5e5e5",
"background": "#0e0e0e",
"foreground": "#cccccc"
}
],

// Add custom keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about keybindings, visit https://aka.ms/terminal-keybindings
"keybindings": [
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{ "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },

// Press Ctrl+Shift+F to open the search box
{ "command": "find", "keys": "ctrl+shift+f" },

// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{
"command": {
"action": "splitPane",
"split": "auto",
"splitMode": "duplicate"
},
"keys": "alt+shift+d"
}
]
}

Q&A

补充

git log, git diff 中文乱码(Hex码)

PowerShell 执行下方

1
2
3
4
5
git config --global core.quotepath false
git config --global gui.encoding utf-8
git config --global i18n.commit.encoding utf-8
git config --global i18n.logoutputencoding utf-8
$env:LESSCHARSET='utf-8'

添加系统环境变量

点击Ok ,完成后,关闭 Windows Terminal,重新打开,输入下方命令验证是否成功

1
$env:LESSCHARSET

解决,无论是 git log,还是 git diff, 中文都显示正常

参考

感谢帮助!