使用 Windows Terminal 連接遠程主機
Intro
Windows Terminal 是微軟新推出來的一個全新的、流行的、功能強大的命令行終端工具。包含很多來社區呼聲很高的特性,例如:多 Tab 支持、富文本、多語言支持、可配置、主題和樣式,支持 emoji 和基於 GPU 運算的文本渲染等等。同時該終端依然符合我們的目標和要求,以確保它保持快速、高效,並且不會消耗大量內存和電源。
在前幾天的微軟開發者 Build 大會上, Windows Terminal 發布了 1.0 正式版,可以從微軟的應用商店進行下載,之前一直用的 XShell 去管理遠程 Linux 主機,用上 Terminal 之后就放棄了 XShell,直接使用 ssh
了,如果你還未開始使用 Windows Terminal ,強烈建議你嘗試一下,也許你會愛不釋手~
使用一覽
上面的截圖中后面選項三個都是我手動添加 Profile,都是 Linux 主機,使用時只需要點擊一下,輸入密碼即可登錄遠程主機,然后就可以在你的遠程主機上盡情玩耍了~~
Windows Terminal 配置文件
配置指南可以參考微軟的官方文檔 https://aka.ms/terminal-documentation/https://github.com/microsoft/terminal/blob/master/doc/user-docs/UsingJsonSettings.md
Github 上的開源主題分享:https://github.com/atomcorp/themes https://atomcorp.github.io/themes/
如果你之前用的 XShell 之類的終端工具喜歡使用 Shift + Insert 來粘貼文本的話也可以配置快捷鍵來實現,使之更符合自己的使用習慣,默認是 Ctrl+Shift+C 復制,Ctrl+Shift+V 粘貼
新建遠程主機 Profile
新建的 Profile 示例配置如下:
{
"name": "weihanli.xyz", // 會顯示在 Tab 的下拉選項中
"tabTitle": "pipeline@weihanli.xyz", // 打開后的 Tab 標題
"colorScheme" : "AdventureTime", // 顏色主題,與下面定義的 schemes 中的主題的名稱對應
"commandline": "ssh pipeline@weihanli.xyz", // 執行的命令
"icon": "C:\\Users\\liweihan\\Pictures\\Saved Pictures\\7604648.jpg" //圖標路徑,不僅支持本地路徑還支持網絡圖標
}
這里我是不需要設置為默認打開的 profile 所以沒有配置 guid,如果需要配置為默認打開的 profile,則需要添加一個唯一的 guid ,然后修改上面的 defaultProfile 的值為新添加的 profile 的 guid 即可
顏色主題配置:
顏色主題我是從 https://atomcorp.github.io/themes/ 這里找了幾個覺得還不錯的主題,可以在這里找自己喜歡的主題,然后再加一些自定義的配置調整,我的顏色主題配置如下:
// Add custom color schemes to this array
// https://atomcorp.github.io/themes/
"schemes":
[
{
"name": "AdventureTime",
"black": "#050404",
"red": "#bd0013",
"green": "#4ab118",
"yellow": "#e7741e",
"blue": "#0f4ac6",
"purple": "#665993",
"cyan": "#70a598",
"white": "#f8dcc0",
"brightBlack": "#4e7cbf",
"brightRed": "#fc5f5a",
"brightGreen": "#9eff6e",
"brightYellow": "#efc11a",
"brightBlue": "#1997c6",
"brightPurple": "#9b5953",
"brightCyan": "#c8faf4",
"brightWhite": "#f6f5fb",
"background": "#1f1d45",
"foreground": "#f8dcc0"
},
{
"name": "Atom",
"black": "#000000",
"red": "#fd5ff1",
"green": "#87c38a",
"yellow": "#ffd7b1",
"blue": "#85befd",
"purple": "#b9b6fc",
"cyan": "#85befd",
"white": "#e0e0e0",
"brightBlack": "#000000",
"brightRed": "#fd5ff1",
"brightGreen": "#94fa36",
"brightYellow": "#f5ffa8",
"brightBlue": "#96cbfe",
"brightPurple": "#b9b6fc",
"brightCyan": "#85befd",
"brightWhite": "#e0e0e0",
"background": "#161719",
"foreground": "#c5c8c6"
},
{
"name": "cyberpunk",
"black": "#000000",
"red": "#ff7092",
"green": "#00fbac",
"yellow": "#fffa6a",
"blue": "#00bfff",
"purple": "#df95ff",
"cyan": "#86cbfe",
"white": "#ffffff",
"brightBlack": "#000000",
"brightRed": "#ff8aa4",
"brightGreen": "#21f6bc",
"brightYellow": "#fff787",
"brightBlue": "#1bccfd",
"brightPurple": "#e6aefe",
"brightCyan": "#99d6fc",
"brightWhite": "#ffffff",
"background": "#332a57",
"foreground": "#e5e5e5"
},
{
"name": "Flat",
"black": "#222d3f",
"red": "#a82320",
"green": "#32a548",
"yellow": "#e58d11",
"blue": "#3167ac",
"purple": "#781aa0",
"cyan": "#2c9370",
"white": "#b0b6ba",
"brightBlack": "#212c3c",
"brightRed": "#d4312e",
"brightGreen": "#2d9440",
"brightYellow": "#e5be0c",
"brightBlue": "#3c7dd2",
"brightPurple": "#8230a7",
"brightCyan": "#35b387",
"brightWhite": "#e7eced",
"background": "#002240",
"foreground": "#2cc55d"
},
{
"name": "Galaxy",
"black": "#000000",
"red": "#f9555f",
"green": "#21b089",
"yellow": "#fef02a",
"blue": "#589df6",
"purple": "#944d95",
"cyan": "#1f9ee7",
"white": "#bbbbbb",
"brightBlack": "#555555",
"brightRed": "#fa8c8f",
"brightGreen": "#35bb9a",
"brightYellow": "#ffff55",
"brightBlue": "#589df6",
"brightPurple": "#e75699",
"brightCyan": "#3979bc",
"brightWhite": "#ffffff",
"background": "#1d2837",
"foreground": "#ffffff"
},
{
"name": "Tomorrow",
"black": "#000000",
"red": "#c82829",
"green": "#718c00",
"yellow": "#eab700",
"blue": "#4271ae",
"purple": "#8959a8",
"cyan": "#3e999f",
"white": "#ffffff",
"brightBlack": "#000000",
"brightRed": "#c82829",
"brightGreen": "#718c00",
"brightYellow": "#eab700",
"brightBlue": "#4271ae",
"brightPurple": "#8959a8",
"brightCyan": "#3e999f",
"brightWhite": "#ffffff",
"background": "#ffffff",
"foreground": "#4d4d4c"
},
{
"name": "Tomorrow Night",
"black": "#000000",
"red": "#cc6666",
"green": "#b5bd68",
"yellow": "#f0c674",
"blue": "#81a2be",
"purple": "#b294bb",
"cyan": "#8abeb7",
"white": "#ffffff",
"brightBlack": "#000000",
"brightRed": "#cc6666",
"brightGreen": "#b5bd68",
"brightYellow": "#f0c674",
"brightBlue": "#81a2be",
"brightPurple": "#b294bb",
"brightCyan": "#8abeb7",
"brightWhite": "#ffffff",
"background": "#1d1f21",
"foreground": "#c5c8c6"
},
{
"name": "Tomorrow Night Blue",
"black": "#000000",
"red": "#ff9da4",
"green": "#d1f1a9",
"yellow": "#ffeead",
"blue": "#bbdaff",
"purple": "#ebbbff",
"cyan": "#99ffff",
"white": "#ffffff",
"brightBlack": "#000000",
"brightRed": "#ff9da4",
"brightGreen": "#d1f1a9",
"brightYellow": "#ffeead",
"brightBlue": "#bbdaff",
"brightPurple": "#ebbbff",
"brightCyan": "#99ffff",
"brightWhite": "#ffffff",
"background": "#002451",
"foreground": "#ffffff"
}
]
More
從上面我們可以看的出來,其實可以玩的有很多,
命令可以根據自己的需要進行定制,上面是連接一個遠程的Linux主機,我們也可以通過 powershell 連接遠程的 Windows 主機,也可以打開在某一個位置打開固定的 shell 等等,
主題可以高度自定義,除了上面的幾個主題用到的顏色,前景色,背景色之外還可以針對 profile 配置背景圖透明度等
快捷鍵綁定自定義,可以讓你的使用習慣一如往常
總之,如果你還沒有用上 Windows Terminal ,強烈建議使用一下,感受一下全新的命令行終端
Reference
- https://aka.ms/terminal-documentation
- https://github.com/microsoft/terminal
- https://github.com/microsoft/terminal/blob/master/doc/user-docs/UsingJsonSettings.md
- https://github.com/kerol2r20/Windows-terminal-context-menu
- https://github.com/atomcorp/themes
- https://www.zhihu.com/question/37181941/answer/695147545