玩轉 Windows Terminal

今天給你們分享一下Windows Terminal的使用及個性化定製。git

1、安裝

該項目的開源地址爲https://github.com/microsoft/terminal,若是想折騰,能夠按照上面的說明本身編譯。不想折騰的直接在microsoft store直接搜索Windows Terminal,會搜到一個Windows Terminal 和一個Windows Terminal Preview版本。github

本文以Preview版爲例。shell

安裝好Windows Terminal Preview以後,默認打開了PowerShell,發現和原來的沒多大區別,顏色像CMD同樣漆黑一片。徹底不像介紹的那麼酷。json

     圖 1windows

 

 不一樣的是它是多Tab的,在標題右側有個下拉菜單,能夠打開其餘工具數組

   圖 2app

 

 如上圖能夠再打開一個CMD標籤。ssh

同時咱們看到了設置選項,下面就開始倒騰一下相關的配置吧。ide

2、配置

點擊【設置】,會打開一個名爲settings.json的文件,大概以下面代碼所示:工具

 

 1 {
 2   "$schema": "https://aka.ms/terminal-profiles-schema",
 3 
 4   "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", //默認打開下面的profiles.List中的哪一個profile,
 5 
 6   // 是否將選中內容自動複製到剪切板,默認是false,若是須要複製,選中內容中點擊鼠標右鍵就實現了複製。若是是true,當選中的時候,就執行復制
 7   "copyOnSelect": false,
 8 
 9   // 複製的時候是否複製文本的樣式,例如顏色、字體等
10   "copyFormatting": false,
11 
12   //profiles配置
13   "profiles": {
14     "defaults": {
15       // 設置通用配置
16     },
17     "list": [
18       {
19         // 針對 powershell.exe 這個profile進行配置.
20         "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
21         "name": "Windows PowerShell",
22         "commandline": "powershell.exe",
23         "hidden": false
24       },
25       {
26         // 針對 cmd.exe 這個profile進行配置.
27         "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
28         "name": "命令提示符",
29         "commandline": "cmd.exe",
30         "hidden": false
31       },
32       {
33         "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
34         "hidden": false,
35         "name": "Azure Cloud Shell",
36         "source": "Windows.Terminal.Azure"
37       }
38     ]
39   },
40 
41   //自定義的color schemes放在這裏
42   "schemes": [
43 
44   ],
45 
46   // 在下面的集合中添加自定義的按鍵命令綁定
47   // 取消組合鍵,請將命令設置爲「 unbound」。
48   "keybindings": [
49     // 在defaults.json中,複製和粘貼已經被綁定到了 Ctrl+Shift+C and Ctrl+Shift+V .
50     // 正兩行又將它們綁定到了Ctrl+C and Ctrl+V.
51     {
52       "command": {
53         "action": "copy",
54         "singleLine": false
55       },
56       "keys": "ctrl+c"
57     },
58     {
59       "command": "paste",
60       "keys": "ctrl+v"
61     },
62 
63     // 按下 Ctrl+Shift+F 打開搜索窗口
64     {
65       "command": "find",
66       "keys": "ctrl+shift+f"
67     },
68 
69     // 按組合鍵 Alt+Shift+D 打開一個新的窗格,注意不是標籤
70     //-「 split」:「 auto」使此窗格向着能提供最大面積的方向打開。
71     //-「 splitMode」:「 duplicate」新窗格使用當前窗格一樣的配置文件。
72     {
73       "command": {
74         "action": "splitPane",
75         "split": "auto",
76         "splitMode": "duplicate"
77       },
78       "keys": "alt+shift+d"
79     }
80   ]
81 }

1. Profile設置:

【圖2】所示的下拉菜單中,列出了"Windows PowerShell"、"命令提示符"和"Azure Cloud Shell"三個選項,爲何是這三項呢?是在profiles的List集合中配置的。能夠看到現有三項正好與圖2中的3項一一對應。

既然是可配置的,那麼咱們是否能夠自定義添加呢?固然是能夠的,下一小節咱們來實驗一下,本節先講現有配置。
第4行的defaultProfile屬性,設置了默認的Profile的guid,能夠看出該guid正是Windows PowerShell的,因此咱們打開Windows Terminal的時候,默認打開的是Windows PowerShell。

2. 複製設置:

第7行: 的"copyOnSelect"指定了是否將選中內容自動複製到剪切板,默認是false。這時若是須要複製,選中內容中點擊鼠標右鍵就實現了複製。若是是true,當選中的時候,就執行復制。
第10行:「copyFormatting」指定了在複製的時候是否複製文本的樣式,例如顏色、字體等。

3. 快捷鍵設置:

第48行,"keybindings"數組設置瞭如何經過一些組合鍵觸發操做命令,例如複製、粘貼、查找等,代碼中已經作了註釋,就不一一說明了。
這裏要說一下經過 "alt+shift+d"打開新窗格,這個不是新tab,是在原窗口中拆分出來的,以下圖

              圖3

新窗格會採用當前窗格的配置方案。能夠按住 alt 鍵,而後使用箭頭鍵在窗格之間移動焦點。
打開了這麼多不知道怎麼關閉?能夠鍵入 ctrl+shift+w 來關閉焦點窗格。 若是隻有一個窗格,ctrl+shift+w 將關閉該選項卡。與往常同樣,關閉最後一個選項卡將關閉該窗口。
若是想要打開新的tab可使用"ctrl+shift+d"。

3. 配色方案設置:

第42行,"schemes"提供了一個空的數組,用於放置自定義的配色方案。 具體介紹見下一節。

 

3、自定義樣式

setting.json 只列出了一些方便咱們配置的選項, 其實系統中已經爲咱們作了許多默認配置。按住alt鍵, 再去點擊設置選項,這時不會打開setting.json, 而是會打開一個名爲default.json的文件,這就是默認的配置文件。

代碼以下,作了摺疊有興趣的能夠看一看。

// THIS IS AN AUTO-GENERATED FILE! Changes to this file will be ignored.
{
    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

    // Launch Settings
    "initialCols": 120,
    "initialRows": 30,
    "launchMode": "default",

    // Selection
    "copyOnSelect": false,
    "copyFormatting": true,
    "wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502",

    // Tab UI
    "alwaysShowTabs": true,
    "showTabsInTitlebar": true,
    "showTerminalTitleInTitlebar": true,
    "tabWidthMode": "equal",

    // Miscellaneous
    "confirmCloseAllTabs": true,
    "startOnUserLogin":  false,
    "theme": "system",
    "rowsToScroll": "system",
    "snapToGridOnResize": true,

    "profiles":
    [
        {
            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
            "name": "Windows PowerShell",
            "commandline": "powershell.exe",
            "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
            "colorScheme": "Campbell",
            "antialiasingMode": "grayscale",
            "closeOnExit": "graceful",
            "cursorShape": "bar",
            "fontFace": "Cascadia Mono",
            "fontSize": 12,
            "hidden": false,
            "historySize": 9001,
            "padding": "8, 8, 8, 8",
            "snapOnInput": true,
            "altGrAliasing": true,
            "startingDirectory": "%USERPROFILE%",
            "useAcrylic": false
        },
        {
            "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
            "name": "Command Prompt",
            "commandline": "cmd.exe",
            "icon": "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
            "colorScheme": "Campbell",
            "antialiasingMode": "grayscale",
            "closeOnExit": "graceful",
            "cursorShape": "bar",
            "fontFace": "Cascadia Mono",
            "fontSize": 12,
            "hidden": false,
            "historySize": 9001,
            "padding": "8, 8, 8, 8",
            "snapOnInput": true,
            "altGrAliasing": true,
            "startingDirectory": "%USERPROFILE%",
            "useAcrylic": false
        }
    ],
    "schemes":
    [
        // A profile can override the following color scheme values:
        //   - "foreground"
        //   - "background"
        //   - "cursorColor"
        {
            "name": "Campbell",
            "foreground": "#CCCCCC",
            "background": "#0C0C0C",
            "cursorColor": "#FFFFFF",
            "black": "#0C0C0C",
            "red": "#C50F1F",
            "green": "#13A10E",
            "yellow": "#C19C00",
            "blue": "#0037DA",
            "purple": "#881798",
            "cyan": "#3A96DD",
            "white": "#CCCCCC",
            "brightBlack": "#767676",
            "brightRed": "#E74856",
            "brightGreen": "#16C60C",
            "brightYellow": "#F9F1A5",
            "brightBlue": "#3B78FF",
            "brightPurple": "#B4009E",
            "brightCyan": "#61D6D6",
            "brightWhite": "#F2F2F2"
        },
        {
            "name": "Campbell Powershell",
            "foreground": "#CCCCCC",
            "background": "#012456",
            "cursorColor": "#FFFFFF",
            "black": "#0C0C0C",
            "red": "#C50F1F",
            "green": "#13A10E",
            "yellow": "#C19C00",
            "blue": "#0037DA",
            "purple": "#881798",
            "cyan": "#3A96DD",
            "white": "#CCCCCC",
            "brightBlack": "#767676",
            "brightRed": "#E74856",
            "brightGreen": "#16C60C",
            "brightYellow": "#F9F1A5",
            "brightBlue": "#3B78FF",
            "brightPurple": "#B4009E",
            "brightCyan": "#61D6D6",
            "brightWhite": "#F2F2F2"
        },
        {
            "name": "Vintage",
            "foreground": "#C0C0C0",
            "background": "#000000",
            "cursorColor": "#FFFFFF",
            "black": "#000000",
            "red": "#800000",
            "green": "#008000",
            "yellow": "#808000",
            "blue": "#000080",
            "purple": "#800080",
            "cyan": "#008080",
            "white": "#C0C0C0",
            "brightBlack": "#808080",
            "brightRed": "#FF0000",
            "brightGreen": "#00FF00",
            "brightYellow": "#FFFF00",
            "brightBlue": "#0000FF",
            "brightPurple": "#FF00FF",
            "brightCyan": "#00FFFF",
            "brightWhite": "#FFFFFF"
        },
        {
            "name": "One Half Dark",
            "foreground": "#DCDFE4",
            "background": "#282C34",
            "cursorColor": "#FFFFFF",
            "black": "#282C34",
            "red": "#E06C75",
            "green": "#98C379",
            "yellow": "#E5C07B",
            "blue": "#61AFEF",
            "purple": "#C678DD",
            "cyan": "#56B6C2",
            "white": "#DCDFE4",
            "brightBlack": "#5A6374",
            "brightRed": "#E06C75",
            "brightGreen": "#98C379",
            "brightYellow": "#E5C07B",
            "brightBlue": "#61AFEF",
            "brightPurple": "#C678DD",
            "brightCyan": "#56B6C2",
            "brightWhite": "#DCDFE4"
        },
        {
            "name": "One Half Light",
            "foreground": "#383A42",
            "background": "#FAFAFA",
            "cursorColor": "#4F525D",
            "black": "#383A42",
            "red": "#E45649",
            "green": "#50A14F",
            "yellow": "#C18301",
            "blue": "#0184BC",
            "purple": "#A626A4",
            "cyan": "#0997B3",
            "white": "#FAFAFA",
            "brightBlack": "#4F525D",
            "brightRed": "#DF6C75",
            "brightGreen": "#98C379",
            "brightYellow": "#E4C07A",
            "brightBlue": "#61AFEF",
            "brightPurple": "#C577DD",
            "brightCyan": "#56B5C1",
            "brightWhite": "#FFFFFF"
        },
        {
            "name": "Solarized Dark",
            "foreground": "#839496",
            "background": "#002B36",
            "cursorColor": "#FFFFFF",
            "black": "#073642",
            "red": "#DC322F",
            "green": "#859900",
            "yellow": "#B58900",
            "blue": "#268BD2",
            "purple": "#D33682",
            "cyan": "#2AA198",
            "white": "#EEE8D5",
            "brightBlack": "#002B36",
            "brightRed": "#CB4B16",
            "brightGreen": "#586E75",
            "brightYellow": "#657B83",
            "brightBlue": "#839496",
            "brightPurple": "#6C71C4",
            "brightCyan": "#93A1A1",
            "brightWhite": "#FDF6E3"
        },
        {
            "name": "Solarized Light",
            "foreground": "#657B83",
            "background": "#FDF6E3",
            "cursorColor": "#002B36",
            "black": "#073642",
            "red": "#DC322F",
            "green": "#859900",
            "yellow": "#B58900",
            "blue": "#268BD2",
            "purple": "#D33682",
            "cyan": "#2AA198",
            "white": "#EEE8D5",
            "brightBlack": "#002B36",
            "brightRed": "#CB4B16",
            "brightGreen": "#586E75",
            "brightYellow": "#657B83",
            "brightBlue": "#839496",
            "brightPurple": "#6C71C4",
            "brightCyan": "#93A1A1",
            "brightWhite": "#FDF6E3"
        },
        {
            "name": "Tango Dark",
            "foreground": "#D3D7CF",
            "background": "#000000",
            "cursorColor": "#FFFFFF",
            "black": "#000000",
            "red": "#CC0000",
            "green": "#4E9A06",
            "yellow": "#C4A000",
            "blue": "#3465A4",
            "purple": "#75507B",
            "cyan": "#06989A",
            "white": "#D3D7CF",
            "brightBlack": "#555753",
            "brightRed": "#EF2929",
            "brightGreen": "#8AE234",
            "brightYellow": "#FCE94F",
            "brightBlue": "#729FCF",
            "brightPurple": "#AD7FA8",
            "brightCyan": "#34E2E2",
            "brightWhite": "#EEEEEC"
        },
        {
            "name": "Tango Light",
            "foreground": "#555753",
            "background": "#FFFFFF",
            "cursorColor": "#000000",
            "black": "#000000",
            "red": "#CC0000",
            "green": "#4E9A06",
            "yellow": "#C4A000",
            "blue": "#3465A4",
            "purple": "#75507B",
            "cyan": "#06989A",
            "white": "#D3D7CF",
            "brightBlack": "#555753",
            "brightRed": "#EF2929",
            "brightGreen": "#8AE234",
            "brightYellow": "#FCE94F",
            "brightBlue": "#729FCF",
            "brightPurple": "#AD7FA8",
            "brightCyan": "#34E2E2",
            "brightWhite": "#EEEEEC"
        }
    ],
    "keybindings":
    [
        // Application-level Keys
        { "command": "closeWindow", "keys": "alt+f4" },
        { "command": "toggleFullscreen", "keys": "alt+enter" },
        { "command": "toggleFullscreen", "keys": "f11" },
        { "command": "openNewTabDropdown", "keys": "ctrl+shift+space" },
        { "command": "openSettings", "keys": "ctrl+," },
        { "command": { "action": "openSettings", "target": "defaultsFile" }, "keys": "ctrl+alt+," },
        { "command": "find", "keys": "ctrl+shift+f" },

        // Tab Management
        // "command": "closeTab" is unbound by default.
        //   The closeTab command closes a tab without confirmation, even if it has multiple panes.
        { "command": "newTab", "keys": "ctrl+shift+t" },
        { "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+shift+1" },
        { "command": { "action": "newTab", "index": 1 }, "keys": "ctrl+shift+2" },
        { "command": { "action": "newTab", "index": 2 }, "keys": "ctrl+shift+3" },
        { "command": { "action": "newTab", "index": 3 }, "keys": "ctrl+shift+4" },
        { "command": { "action": "newTab", "index": 4 }, "keys": "ctrl+shift+5" },
        { "command": { "action": "newTab", "index": 5 }, "keys": "ctrl+shift+6" },
        { "command": { "action": "newTab", "index": 6 }, "keys": "ctrl+shift+7" },
        { "command": { "action": "newTab", "index": 7 }, "keys": "ctrl+shift+8" },
        { "command": { "action": "newTab", "index": 8 }, "keys": "ctrl+shift+9" },
        { "command": "duplicateTab", "keys": "ctrl+shift+d" },
        { "command": "nextTab", "keys": "ctrl+tab" },
        { "command": "prevTab", "keys": "ctrl+shift+tab" },
        { "command": { "action": "switchToTab", "index": 0 }, "keys": "ctrl+alt+1" },
        { "command": { "action": "switchToTab", "index": 1 }, "keys": "ctrl+alt+2" },
        { "command": { "action": "switchToTab", "index": 2 }, "keys": "ctrl+alt+3" },
        { "command": { "action": "switchToTab", "index": 3 }, "keys": "ctrl+alt+4" },
        { "command": { "action": "switchToTab", "index": 4 }, "keys": "ctrl+alt+5" },
        { "command": { "action": "switchToTab", "index": 5 }, "keys": "ctrl+alt+6" },
        { "command": { "action": "switchToTab", "index": 6 }, "keys": "ctrl+alt+7" },
        { "command": { "action": "switchToTab", "index": 7 }, "keys": "ctrl+alt+8" },
        { "command": { "action": "switchToTab", "index": 8 }, "keys": "ctrl+alt+9" },

        // Pane Management
        { "command": "closePane", "keys": "ctrl+shift+w" },
        { "command": { "action": "splitPane", "split": "horizontal" }, "keys": "alt+shift+-" },
        { "command": { "action": "splitPane", "split": "vertical" }, "keys": "alt+shift+plus" },
        { "command": { "action": "resizePane", "direction": "down" }, "keys": "alt+shift+down" },
        { "command": { "action": "resizePane", "direction": "left" }, "keys": "alt+shift+left" },
        { "command": { "action": "resizePane", "direction": "right" }, "keys": "alt+shift+right" },
        { "command": { "action": "resizePane", "direction": "up" }, "keys": "alt+shift+up" },
        { "command": { "action": "moveFocus", "direction": "down" }, "keys": "alt+down" },
        { "command": { "action": "moveFocus", "direction": "left" }, "keys": "alt+left" },
        { "command": { "action": "moveFocus", "direction": "right" }, "keys": "alt+right" },
        { "command": { "action": "moveFocus", "direction": "up" }, "keys": "alt+up" },

        // Clipboard Integration
        { "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+shift+c" },
        { "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+insert" },
        { "command": "paste", "keys": "ctrl+shift+v" },
        { "command": "paste", "keys": "shift+insert" },

        // Scrollback
        { "command": "scrollDown", "keys": "ctrl+shift+down" },
        { "command": "scrollDownPage", "keys": "ctrl+shift+pgdn" },
        { "command": "scrollUp", "keys": "ctrl+shift+up" },
        { "command": "scrollUpPage", "keys": "ctrl+shift+pgup" },

        // Visual Adjustments
        { "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+=" },
        { "command": { "action": "adjustFontSize", "delta": -1 }, "keys": "ctrl+-" },
        { "command": "resetFontSize", "keys": "ctrl+0" }
    ]
}
View Code

 

這個文件的結構和Setting.json文件的結構基本上是同樣的,只不過系統提供了比較多的默認配置。  咱們若是想寫配置也能夠用做參考。

1.系統提供的配色方案

能夠看到在default.json"schemes"數組中提供了多種配色方案,例如"Campbell"、"Campbell Powershell"、"Vintage"等。

Campbell:

 

Solarized Light:

 

 

 

2. 配色方案的使用

使用方法就是在"profiles"節點中進行設置,例如Setting文件中作以下配置:

  //profiles配置
  "profiles": {
    "defaults": {
      // 設置通用配置
      "colorScheme": "Solarized Light"
    },
    "list": [
      {
        // 針對 cmd.exe 這個profile進行配置.
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
        "name": "命令提示符",
        "commandline": "cmd.exe",
        "hidden": false,
        "colorScheme": "Tango Light"
      }
      // 。。。。。。。。。。。。。。
    ]
  },

能夠看到代碼中分別針對「default"和」cmd.exe「作了"colorScheme": "Solarized Light"和"colorScheme": "Tango Light"的配置,這使每一個tab均默認採用名爲"Solarized Light"的配色方案,cmd的tab除外,由於專門在cmd的節點中定義的優先級要高於」default「的默認配置。

這也使咱們簡單瞭解了"profiles"的配置方式。咱們能夠像配置配色方案同樣配置其餘屬性。例如能夠經過以下代碼將默認的背景顏色設置成紅色(挺醜的)。

    "defaults": {
      // 設置通用配置
      "background": "#FF0000"
    },

固然這只是例子,關於這樣的樣式設置仍是經過建議自定義colorScheme來實現(見下節)。不僅是樣式,還能夠設置光標、鍵盤、tab的標題等,這裏就不一一介紹了,詳見本文底部的官方連接。

3. 自定義colorScheme

 本節咱們自定義一個colorScheme。

  //自定義的color schemes放在這裏
  "schemes": [
    {
      "name": "FlyLolo Test",
      "cursorColor": "#5F04B4",
      "background": "#FFFFFF",
      "selectionBackground": "#D8F781",
      "black": "#3C5712",
      "blue": "#17b2ff",
      "brightBlack": "#749B36",
      "brightBlue": "#27B2F6",
      "brightCyan": "#13A8C0",
      "brightGreen": "#89AF50",
      "brightPurple": "#F2A20A",
      "brightRed": "#F49B36",
      "brightWhite": "#741274",
      "brightYellow": "#991070",
      "cyan": "#3C96A6",
      "foreground": "#6A0888",
      "green": "#6AAE08",
      "purple": "#991070",
      "red": "#8D0C0C",
      "white": "#6E386E",
      "yellow": "#991070"
    }
  ]

設置了Windows PowerShell的背景和毛玻璃效果:

      {
        // 針對 powershell.exe 這個profile進行配置.
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
        "name": "Windows PowerShell",
        "commandline": "powershell.exe",
        "hidden": false,
        "colorScheme": "FlyLolo Test",
        "useAcrylic": true,
        "acrylicOpacity": 0.7,
        "backgroundImage": "D://1.png",
        "backgroundImageStretchMode": "none",
        "backgroundImageAlignment": "bottomRight",
        "backgroundImageOpacity": "0.6"
      },

最終效果以下圖。 背景圖我的建議不要弄全屏的炫圖,好看,但打字時就不實用了。

 

 

 

4、鏈接CentOS

 以前鏈接CentOS習慣使用PuTTY,如今是否能夠經過Windows Terminal來實現呢? 在第二節咱們知道能夠在profiles的List集合中配置新的下拉選項功能。

在List中添加以下代碼:

{
    "guid": "{439227e1-65b3-4a60-a518-74afeca0c7c0}",
    "hidden": false,
    "name": "CentOS",
    "commandline": "ssh 用戶名@域名orIP -p 端口號",
    "icon": "ms-appdata:///Local/Centos.png"
}

icon 須要本身設置,VS右鍵點擊settings.json標籤,找到該文件所在的位置,

 

 

 網上找了個centOS的圖標,, 放在settings.json的相同目錄下,配置中就能夠經過 "icon": "ms-appdata:///Local/Centos.png"  這樣的路徑設置了。

這樣就配置完了,保存settings.json文件,無需從新啓動Windows Terminal就能夠在下拉選項中找到CentOS了,點擊該選項,會出現以下窗口,輸入密碼登陸成功。

 

參考地址:https://docs.microsoft.com/zh-cn/windows/terminal/

相關文章
相關標籤/搜索