总述
做为一个码农,基本工作就是登录到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到服务器工作这件事已经绰绰有余,而且各种快捷键非常方便。
还有一些其他技巧可以查看官方网页
如有一些其他需求和建议,欢迎留言。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。