深度优先

这个家伙好懒,除了文章什么都没留下

0%

【工具】WindowsTerminal设置

转自:https://blog.oldzeng.com/archives/windowsterminalconfig

WindowsTerminal 更新到0.7了, 支持分屏和移动标签, 真香。 但是现在其配置文件和基本设置还不是特别好上手, 有点类似早期的VS Code ,所以这里记录一下常规的设置, 以便使用。

更新日期: 2020-12-26, 目前版本: 1.3

安装

推荐直接从Windows应用商店下载

  • 快捷键:
    • Alt Shift + : 竖向分屏
    • Alt Shift - : 横向分屏
    • Alt Shift 方向键 : 调整分屏大小
    • Alt 方向键 : 切换当前分屏

基本配置

如果在之前已经安装过了的话, 升级之后, 配置文件还是老版本的配置文件的样子,这样导致一个问题就是会有一个额外的标题栏, 于是打开就会出现有两个标题栏的丑东西。 解决的办法也比较简单, 把配置文件换成新的配置文件的样子就可以了:

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
// 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}",

"profiles":
[
{
// Make changes here to the powershell.exe profile
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "PowerShell",
"commandline": "powershell.exe",
"hidden": false,
"useAcrylic": true,
"cursorShape": "filledBox",
"scrollbarState": "hidden"
},
{
// Make changes here to the cmd.exe profile
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "cmd",
"commandline": "CMD",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
}
],

// Add custom color schemes to this array
"schemes": [],

// Add any keybinding overrides to this array.
// To unbind a default keybinding, set the command to "unbound"
"keybindings": []
}

到这一步, 东西“又不是不能用”了, 下面做一些锦上添花的东西

优化配置

1. 添加到右键菜单

这么个刚需的东西现在竟然需要手动配置, 有点不太友好。 实现的原理也很简单, 就是在注册表中写入一条右键菜单配置, 为了美观一点,我么给它加上一个图标:

  1. 下载图标文件, 将图标文件保存到某个目录中,可以在Local目录下新建个子目录, 如: C:\Users\[用户名]\AppData\Local\terminal 喜欢原理cmd图标的也可以用这个: https://raw.githubusercontent.com/microsoft/terminal/master/res/console.ico

  2. 配置注册表 将下面代码保存成aa.reg文件, 命名随意, 路径替换, 双击运行。

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

    [HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
    @="Terminal here"
    "Icon"="C:\\Users\\[用户名]\\AppData\\Local\\terminal\\terminal.ico"

    [HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
    @="C:\\Users\\[用户名]\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"
  3. 修改配置 上面一步, 成功实现添加右键菜单, 但是打开之后都是默认路径。 所以需要手动改一下路径。 配置文件的每一个profile配置下都加上这么一行:

    1
    "startingDirectory": "./"

2. 自定义主题

原生主题FFF字色有点晃眼, 此时自己可以定义一套Schema来自定义主题, 我现在用的这份主题配置不是原创, 网上抄的, 但是找不到源码了。 具体的做法就是在Schema数组中添加一个对象, 配置好对应的颜色, 然还在想要使用主题的 Profile 对象中指定 colorScheme 就可以了。 最后的配置放在最后

3. 设置背景透明和配置图片

这两个属性设置也是在Profile 中设置, 现在的设置也很简单

1
2
3
4
5
"useAcrylic": true,        // 打开透明效果
"acrylicOpacity": 0.8, // 背景透明度

"backgroundImage": "E:\\Images\\wallpaper\\1.jpg", // 背景图片效果
"backgroundImageOpacity": 0.3, // 背景图片透明度

4. 设置SSH连接快捷方式

设置SSH远程连接也是一样, 通过添加一个Profile就可以完成. 具体做法是, 添加一个新的Profile, 设置基本属性后, 添加一条 commonLine 的属性, 如:

code

1
"commonLine": "ssh someone@123.231.132.123`

为了省去输入密码的步骤, 可以将ssh公钥上传至对应的服务器中, 比如对应上面这条配置, 具体做法如下:

  1. 找到123.231.132.123机器上面/home/someone/.ssh/authorized_keys 文件, 如果没有, 则依次创建
  2. 复制本机公钥的内容(C:\Users\[用户名].ssh\id_rsa.pub) 到上面创建的文件中。

集成 GitBash

如果电脑安装了 Git, 可以将 GitBash 集成到 Terminal 中, 体验效果炫酷且无缝切换的客户端. 具体的方法就是配置一个新的Profile , 需要注意的是, 执行文件的路径, 不是 Git 安装目录下的 git-bash.exe , 而是 bin/bash.exe , 然后再找个合适的图标就好了, 参考图标:

code

1
2
3
4
5
6
{
"guid": "{714caed7-ef94-468e-b73c-797c4b064fa6}",
"name": "Git",
"icon": "C:\\Program Files\\Git\\git.png",
"commandline": "C:\\Program Files\\Git\\bin\\bash.exe"
}

集成 WSL

如果 Windows 安装了 WSL, 会自动配置一个对应操作系统的 Profile, 如果没有的话, 也可以自己配置, 大概内容如下:

code

1
2
3
4
5
{
"guid": "{98580abb-df41-5a69-97cc-d558b1e5c68a}",
"name": "centos8",
"source": "Windows.Terminal.Wsl"
}

搞定。


最终效果:

附上配置文件:

code

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
// 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}",

"profiles":
[
{
// Make changes here to the powershell.exe profile
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "PowerShell",
"commandline": "powershell.exe",
"hidden": false,
"startingDirectory": "./",
"fontFace": "Cascadia Code",
"acrylicOpacity": 0.8,
"useAcrylic": true,
"colorScheme": "Firewatch",
"cursorColor": "#FFFFFF",
"cursorShape": "filledBox",
"fontSize": 12,
"padding": "8, 8, 8, 8",
"backgroundImage": "E:\\Images\\wallpaper\\1.jpg",
"backgroundImageOpacity": 0.3,
"scrollbarState": "hidden"
},
{
// Make changes here to the cmd.exe profile
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "cmd",
"commandline": "CMD",
"hidden": false,
"startingDirectory": "./",
"fontFace": "Cascadia Code"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure",
"startingDirectory": "./",
"fontFace": "Cascadia Code"
}
],

// Add custom color schemes to this array
"schemes": [
{
"name": "Firewatch",
"black": "#585f6d",
"red": "#d95360",
"green": "#5ab977",
"yellow": "#dfb563",
"blue": "#4d89c4",
"purple": "#d55119",
"cyan": "#44a8b6",
"white": "#e6e5ff",
"brightBlack": "#585f6d",
"brightRed": "#d95360",
"brightGreen": "#5ab977",
"brightYellow": "#dfb563",
"brightBlue": "#4c89c5",
"brightPurple": "#d55119",
"brightCyan": "#44a8b6",
"brightWhite": "#e6e5ff",
"background": "#1e2027",
"foreground": "#f3f3f3"
}
],

// Add any keybinding overrides to this array.
// To unbind a default keybinding, set the command to "unbound"
"keybindings": []
}