原文:https://sspai.com/post/59380 选主题:https://github.com/mbadolato/iTerm2-Color-Schemes 搜主题:https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/windowsterminal

文件位置:

首先,我们进入 Windows Terminal 的设置文件。在 Windows Terminal 的下拉菜单中,选择 设置 。
Windows Terminal 美化 - 图1
跳转到设置的的页面,点击左下角的 打开JSON文件 ,这样我们就打开了JSON文件。

或者 直接 使用路径进入:C:\Users\Administrator\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState

Windows Terminal 美化 - 图2

了解结构:

Windows Terminal 的配置文件是一个 JSON 格式的文件,我们会在其中定义全部 Windows Terminal 的属性。简单来讲,这个配置文件包含了如下的几个部分:

  • 全局属性:位于 JSON 最外侧,包含有设置亮暗主题、默认 Profile 等项目的配置。
  • 环境入口 **profiles**:一个列表,其中包含有 Windows Terminal 下拉菜单中唤起的各种环境(比如打开 PowerShell 环境、WSL 环境或 SSH 至远程服务器的环境……)与各种环境里 Windows Terminal 的显示方案(比如字体、背景、色彩方案等)。
  • 配色主题 **schemes**:一个配色方案列表,其中包含有 Windows Terminal 在上一项「环境入口」中可以调用的「色彩主题」。
  • 快捷键绑定 **keybindings**:自定义快捷键。

Windows Terminal 美化 - 图3
熟悉了 Windows Terminal 配置文件的各项含义之后,我们即可开始对 Windows Terminal 的各项属性进行配置。

更换背景色:

我们先来更换一个背景,注意放置的位置是在 “profiles” 下的 defaults 下面。

  1. "background": "#013456", // 背景色
  2. "acrylicOpacity": 0.8, // 背景透明度
  3. "useAcrylic": true, // 启用毛玻璃

image.png
Windows Terminal 的环境配置中可以设置其调用命令(commandline)、字体(fontFace)、颜色方案(colorScheme)、背景颜色(background)与背景图片(backgroundImage)等等。

我们在把更换一个背景图片试试

更换背景图:

有些教程会建议放在 Windows Terminal 安装目录 C:\Users\{用户名}\AppData\Local\Packages\``Microsoft.WindowsTerminal_8wekyb3d8bbwe 里面的 **RoamingState** 这一文件夹,其实这里没必要。

如果你用的是上面的方法,图片放在了 RoamingState 文件夹里,下面的路径必须是 ms-appdata:///roaming/ 开头,代码如下:

  1. "backgroundImage": "ms-appdata:///roaming/a.jpg", // 背景图位置(修改你的图片名称)
  2. "backgroundImageStretchMode": "uniformToFill", // 设置背景图片伸缩模式为「按比例放大」
  3. "backgroundImageOpacity": 0.6 // 图片透明度

image.png
如果你不想用上面的方法,就想直接用我网盘的图片,只需要修改你的图片地址即可(注意用反斜杠或双斜杠)。

  1. "backgroundImage":"D:\\OneDrive\\Todo\\@_.jpg", // 背景图位置(修改你的图片名称)
  2. "backgroundImageStretchMode": "uniformToFill", // 设置背景图片伸缩模式为「按比例放大」
  3. "backgroundImageOpacity": 0.1, // 图片透明度

Windows Terminal 美化 - 图6
这样,我们就得到了一个非常 Windows 风格的 PowerShell 终端环境:
image.png
当然,我们同样可以为其他环境配置相应的背景图案。为 Windows Terminal 的环境设置背景,还可以提示我们当前所处的位置,防止在生产环境做出错误的操作等。不过我目前没有这方面的要求,跳过。

  1. ![](https://cdn.nlark.com/yuque/0/2021/png/85597/1616809473937-20985e94-b155-4b88-b633-fb4bb5558483.png#crop=0&crop=0&crop=1&crop=1&height=322&id=aqsVF&originHeight=322&originWidth=607&originalType=binary&ratio=1&rotation=0&showTitle=false&size=0&status=done&style=none&title=&width=607)

更换配色主题:

Windows Terminal 的色彩主题同样是 JSON 文件,我们可以在上文介绍的 profiles.json 文件的 schemes 属性处,添加自定义的色彩主题。

我们先来 iTerm2 Color Schemes 里选配色,我这里选择了一个 Duotone Dark 主题色,然后我们在 windowsterminal 列表里搜索 Duotone Dark
image.png
点进去,复制里面的参数,放在 schemes 下的 中括号里:
image.png
之后,我们在 Windows Terminal 配置文件里,定义使用相应的「色彩主题」,即可让这一环境的配色方案生效:

  1. "colorScheme": "Duotone Dark" // 定义主题色

image.png
这样,我们的主题就配置好了。
image.png
另外,细心的小伙伴发现了,我们既设置了背景图,又设置了主题,系统用哪个呢?答案是都用了,我们可以修改下背景图的透明度看下,这里我修改为0.2,结果如下图:
image.png

好了,我们的美化完成,里面还有字体设置和快捷键设置,方式同理,这里就不赘述了。

更改默认终端:

默认是打开powershell,我经常使用的是命令提示符(小黑窗)
image.png

主题预览:

上面做记录,最后发现上面的主题色调太显眼,太容易疲惫,所以找了几个我比较喜欢的主题,下面有预览图。
注意:记得修改你的图片地址和文件名哦!

image.png
image.png
image.png
image.png
image.png

我的配置

不同电脑的终端ID是不同的,记得更换(有三种guid,每台电脑的都不同,对应的是 39行、46行、52行)
这里面的 guid 只能用自己电脑的,如果改错了,无法打开,就清空后保存再次打开就恢复默认了。

  1. // This file was initially generated by Windows Terminal 1.6.10571.0
  2. // It should still be usable in newer versions, but newer versions might have additional
  3. // settings, help text, or changes that you will not see unless you clear this file
  4. // and let us generate a new one for you.
  5. // To view the default settings, hold "alt" while clicking on the "Settings" button.
  6. // For documentation on these settings, see: https://aka.ms/terminal-documentation
  7. {
  8. "$schema": "https://aka.ms/terminal-profiles-schema",
  9. "defaultProfile": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", // 默认终端ID
  10. // You can add more global application settings here.
  11. // To learn more about global settings, visit https://aka.ms/terminal-global-settings
  12. // If enabled, selections are automatically copied to your clipboard.
  13. "copyOnSelect": false,
  14. // If enabled, formatted data is also copied to your clipboard
  15. "copyFormatting": false,
  16. // A profile specifies a command to execute paired with information about how it should look and feel.
  17. // Each one of them will appear in the 'New Tab' dropdown,
  18. // and can be invoked from the commandline with `wt.exe -p xxx`
  19. // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
  20. "profiles": {
  21. "defaults": {
  22. "backgroundImage": "D:\\OneDrive\\Eagle.library\\images\\JY9IIUHX65L6X.info\\Work Overtime.jpg", // 背景图位置
  23. "backgroundImageStretchMode": "uniformToFill", // 设置背景图片伸缩模式为「按比例放大」
  24. "backgroundImageOpacity": 0.12, // 设置透明度
  25. "colorScheme": "AtelierSulphurpool", // 定义主题色
  26. "useAcrylic": true, // 启用毛玻璃
  27. "acrylicOpacity": 0.9, //毛玻璃透明度,不加它默认就是0.5
  28. "fontFace": "Consolas", // 字体
  29. "fontSize": 12 // 字号
  30. },
  31. "list": [{
  32. // Make changes here to the powershell.exe profile.
  33. "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
  34. "name": "Windows PowerShell",
  35. "commandline": "powershell.exe",
  36. "hidden": false
  37. },
  38. {
  39. // Make changes here to the cmd.exe profile.
  40. "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
  41. "name": "命令提示符",
  42. "commandline": "cmd.exe",
  43. "hidden": false
  44. },
  45. {
  46. "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
  47. "hidden": false,
  48. "name": "Azure Cloud Shell",
  49. "source": "Windows.Terminal.Azure"
  50. }
  51. ]
  52. },
  53. // Add custom color schemes to this array.
  54. // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
  55. "schemes": [{
  56. "name": "AtelierSulphurpool",
  57. "black": "#202746",
  58. "red": "#c94922",
  59. "green": "#ac9739",
  60. "yellow": "#c08b30",
  61. "blue": "#3d8fd1",
  62. "purple": "#6679cc",
  63. "cyan": "#22a2c9",
  64. "white": "#979db4",
  65. "brightBlack": "#6b7394",
  66. "brightRed": "#c76b29",
  67. "brightGreen": "#293256",
  68. "brightYellow": "#5e6687",
  69. "brightBlue": "#898ea4",
  70. "brightPurple": "#dfe2f1",
  71. "brightCyan": "#9c637a",
  72. "brightWhite": "#f5f7ff",
  73. "background": "#202746",
  74. "foreground": "#979db4",
  75. "cursorColor": "#979db4",
  76. "selectionBackground": "#5e6687"
  77. },
  78. {
  79. "name": "Subliminal",
  80. "black": "#7f7f7f",
  81. "red": "#e15a60",
  82. "green": "#a9cfa4",
  83. "yellow": "#ffe2a9",
  84. "blue": "#6699cc",
  85. "purple": "#f1a5ab",
  86. "cyan": "#5fb3b3",
  87. "white": "#d4d4d4",
  88. "brightBlack": "#7f7f7f",
  89. "brightRed": "#e15a60",
  90. "brightGreen": "#a9cfa4",
  91. "brightYellow": "#ffe2a9",
  92. "brightBlue": "#6699cc",
  93. "brightPurple": "#f1a5ab",
  94. "brightCyan": "#5fb3b3",
  95. "brightWhite": "#d4d4d4",
  96. "background": "#282c35",
  97. "foreground": "#d4d4d4",
  98. "cursorColor": "#c7c7c7",
  99. "selectionBackground": "#484e5b"
  100. }
  101. ],
  102. // Add custom actions and keybindings to this array.
  103. // To unbind a key combination from your defaults.json, set the command to "unbound".
  104. // To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
  105. "actions": [
  106. // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
  107. // These two lines additionally bind them to Ctrl+C and Ctrl+V.
  108. // To learn more about selection, visit https://aka.ms/terminal-selection
  109. {
  110. "command": {
  111. "action": "copy",
  112. "singleLine": false
  113. },
  114. "keys": "ctrl+c"
  115. },
  116. {
  117. "command": "paste",
  118. "keys": "ctrl+v"
  119. },
  120. // Press Ctrl+Shift+F to open the search box
  121. {
  122. "command": "find",
  123. "keys": "ctrl+shift+f"
  124. },
  125. // Press Alt+Shift+D to open a new pane.
  126. // - "split": "auto" makes this pane open in the direction that provides the most surface area.
  127. // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
  128. // To learn more about panes, visit https://aka.ms/terminal-panes
  129. {
  130. "command": {
  131. "action": "splitPane",
  132. "split": "auto",
  133. "splitMode": "duplicate"
  134. },
  135. "keys": "alt+shift+d"
  136. }
  137. ]
  138. }