總述
做為一個碼農,基本工作就是登錄到linux服務器上幹活。雖然有VNC可用,但架不住圖形界面怎麼都不如終端流暢啊,所以大多數時候還是用ssh登錄到服務器在終端下編碼,編譯,運行。
免費的ssh客户端還是有的,之前也用過putty(及各種變種),podarosa, mobaxterm, xshell。
之前xshell的免費版是沒限制的,xshell是所有ssh客户端中最好用的,所以一直想買個正版支持一下,無奈這貨真有點貴,99美刀一年。
無意之中有人提了一嘴windows terminal, 這一翻折騰後,發現竟然想要的功能竟然都不缺,在某些方面應該比xshell還容易定製,關鍵是可以配置的非常漂亮,完全不遜於xshell。
安裝
最方便的方式是從Microsoft Store安裝。
如果從github release page安裝的話,則無法自動更新
win10已經內嵌ssh client,無需安裝,可以直接使用
啓動
在搜索框裏直接輸入windows terminal就會有相應的app
特性
- 多標籤頁 (可以通過
ctrl+shift+t來打開新的標籤頁,或通過+旁邊的按鈕) -
多面板
alt+shift++: 打開垂直面板alt+shift+-: 打開水平面板alt+shift+D: 打開一個和目前一樣的面板
- 可配置字體,配色方案
- 可配置快捷鍵
- 可設定命令或字符片斷
- 可設定標籤名稱和顏色 (在標籤上右擊)
命令輸入
ctrl+shift+p會打開命令窗口,前面可以看到支持的所有command
如果要輸入wt命令,那麼用del鍵把>刪除
配置
通過ctrl+,可以打開用户配置文件,json格式
快捷鍵
基本結構就是command和keys
"actions":
[
// 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"
},
{
"command":
{
"action": "switchToTab",
"index": 0
},
"keys": "alt+1"
},
{
"command":
{
"action": "switchToTab",
"index": 1
},
"keys": "alt+2"
},
{
"command":
{
"action": "switchToTab",
"index": 2
},
"keys": "alt+3"
},
{
"command":
{
"action": "switchToTab",
"index": 3
},
"keys": "alt+4"
},
{
"command":
{
"action": "switchToTab",
"index": 4
},
"keys": "alt+5"
},
{
"command":
{
"action": "switchToTab",
"index": 5
},
"keys": "alt+6"
},
{
"command":
{
"action": "switchToTab",
"index": 6
},
"keys": "alt+7"
},
{
"command":
{
"action": "switchToTab",
"index": 7
},
"keys": "alt+8"
},
{
"command":
{
"action": "switchToTab",
"index": 8
},
"keys": "alt+9"
},
{
"command":
{
"action": "closeTab",
"index": 100
},
"keys": "ctrl+shift+w"
},
{
"command":
{
// use \n for linux
"action": "sendInput",
"input": "source ~/.uzsh/xlm20.zshrc\n"
},
"keys": "ctrl+1"
},
{
"command":
{
// use \r for windows
"action": "sendInput",
"input": "ssh -t harriszh@sw02 \"zsh\"\r"
},
"keys": "ctrl+2"
},
// 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"
}
],
命令和代碼片斷
如上面所標,有一個特殊的命令是sendInput, 可以通過這個命令來做一個定製化別名
注意在linux下用\n做換行,而在windows下用\r做換行
{
"command":
{
// use \n for linux
"action": "sendInput",
"input": "source ~/.uzsh/xlm20.zshrc\n"
},
"keys": "ctrl+1"
},
{
"command":
{
// use \r for windows
"action": "sendInput",
"input": "ssh -t harriszh@sw02 \"zsh\"\r"
},
"keys": "ctrl+2"
},
選擇複製
像linux一樣,一旦選中文字就拷貝到系統粘貼板
"copyOnSelect": true,
profiles
這裏定義了幾個全局配置, 它們命運對應ctrl+shift+<n>
"profiles":
{
"defaults": {},
"list":
[
{
"acrylicOpacity": 1.0,
"colorScheme": "Gruvbox Dark",
"commandline": "powershell.exe",
"fontFace": "DejaVuSansMono Nerd Font Mono",
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"hidden": false,
"name": "Windows PowerShell",
"useAcrylic": true
},
{
"commandline": "cmd.exe",
"experimental.retroTerminalEffect": true,
"fontFace": "Consolas",
"foreground": "#00FF00",
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"hidden": false,
"name": "Command Prompt"
},
{
"commandline": "ssh -t harriszh@sw02 \"cd /lan/harriszh && zsh\"",
"fontFace": "DejaVuSansMono Nerd Font Mono",
"guid": "{3b6e258c-bd69-43af-9365-69b153b0ece6}",
"name": "sw02",
"colorScheme": "Gruvbox Dark",
"tabTitle": "sw02",
"useAcrylic": false,
"acrylicOpacity": 0.5,
},
{}
]
},
配色方案
如上面設置中有一項為colorScheme,window terminal內嵌一些方案,更多的可以網上搜索,我比較滿意的是Gruvbox Dark.
"schemes":
[
{
"background": "#1E1E1E",
"black": "#1E1E1E",
"blue": "#377375",
"brightBlack": "#7F7061",
"brightBlue": "#719586",
"brightCyan": "#7DB669",
"brightGreen": "#AAB01E",
"brightPurple": "#C77089",
"brightRed": "#F73028",
"brightWhite": "#E6D4A3",
"brightYellow": "#F7B125",
"cursorColor": "#E6D4A3",
"cyan": "#578E57",
"foreground": "#E6D4A3",
"green": "#868715",
"name": "Gruvbox Dark",
"purple": "#A04B73",
"red": "#BE0F17",
"selectionBackground": "#E6D4A3",
"white": "#978771",
"yellow": "#CC881A"
},
]
多面板
可以使用快捷鍵,也可以用命令來做更詳細的控制
比如: alt+shift+-或alt_shift++
也可以通過ctrl+shift+p調出命令窗口來做詳細控制
下面是在命令窗口(ctrl+shift+p)中輸入split-pane -H -p "pc2"的效果
效果
如果下所示,黑色系下非常清晰。字體是nerd字體,這需要從網上下載,這樣可以顯示一些如文件夾,文件,圖形之類的符號
總結
通過上面的配置後,對於ssh到服務器工作這件事已經綽綽有餘,而且各種快捷鍵非常方便。
還有一些其他技巧可以查看官方網頁
如有一些其他需求和建議,歡迎留言。