自 2015 年开始,主页君在 linux 桌面不是很好用与 windows 命令行不是很好用的左右纠结下,投入了 mac 的怀抱,始终觉得 MacOS 是服务端开发工程师的不二之选,包括其支持的 Posix 协议的一系列系统调用、原生 Terminal 以及 iTerm2 等的便捷,X Windows 的灵活等等优势,但唯一的不足是相比于 windows 用户量仍然比较少,这导致了一些应用的缺失,尤其是 windows 上的 office 全家桶、各种银行客户端都难以被替代,只能通过偶尔切换到 Boot camp 助理中的 windows 来处理。 然而,一些情况在慢慢发生着变化,windows 10 多桌面诞生以来,主页君就开始将关注的目光慢慢移向 windows,虽然彼时经过尝试,对 win10 的多桌面体验仍然觉得不尽人意,但到 2017 年末,主页君体验 WSL 后,终于决定抛弃 MacOS 阵营,回归 windows 怀抱,对于开发者来说,windows 已经变得越来越友好,至少他正在做着一系列的努力来迎合开发者的喜好。 关于 WSL 的安装和使用,可以参看: Win10 集成的 linux 子系统 WSL 的安装与使用
powershell 的不断迭代让我看到 windows 作为一个开发工具的未来,但最令我欣喜的,是今年(2019)5月7日,微软在 Build 开发者大会上公布了官方正在开发的新款命令行界面 — Windows Terminal,随后代码被放到 github 后,迅速增长的 star,也让所有人都看到了大家对于这一项目的期待。 6月21日,Microsoft Store 里正式上架了万众期待的 Windows Terminal 预览版,虽然只是预览版,但这也是“新媳妇上轿 — 头一回”,主页君也是第一时间安装和体验了 Windows Terminal 预览版,本文和大家分享一下主页君的初体验。
既然已经上架到 Microsoft Store,安装就变得非常方便,省去了之前尝鲜时不得不走的编译之路。
首先跟新系统到 1903 版本(或以上),Microsoft Store 中搜索并点击获取即可。
安装好后,打开 Windows Terminal,默认打开了一个与之前 cmd 非常类似的窗口,只有一个标签,连接到了主页君的 wsl bash。
界面十分简洁,可以点击的部分可以看到右侧有一个 + 号和一个下拉箭头,打开下拉箭头可以看到预先配置好的三个选项 — wsl、cmd、powershell。 点击 settings,令人意外的是,竟然跳转到文本编辑器,打开了一个 profiles.json 文件,不过这个 json 文件结构十分清晰,简单易懂,配置项一目了然,经过一些修改,主页君实现了下图配置,添加了所需要的一些 shell:
毛玻璃的外观效果确实漂亮,但是主页君并不十分喜欢,没有做相应配置,也没有换背景,喜欢的朋友可以自己尝试一下,如果背景搭配一张有趣的 gif,效果真是翻倍。
{
"globals" :
{
"alwaysShowTabs" : true,
"defaultProfile" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"initialCols" : 120,
"initialRows" : 30,
"keybindings" :
[
{
"command" : "closeTab",
"keys" :
[
"ctrl+shift+w"
]
},
{
"command" : "newTab",
"keys" :
[
"ctrl+t"
]
},
{
"command" : "newTabProfile0",
"keys" :
[
"ctrl+shift+1"
]
},
{
"command" : "newTabProfile1",
"keys" :
[
"ctrl+shift+2"
]
},
{
"command" : "newTabProfile2",
"keys" :
[
"ctrl+shift+3"
]
},
{
"command" : "newTabProfile3",
"keys" :
[
"ctrl+shift+4"
]
},
{
"command" : "newTabProfile4",
"keys" :
[
"ctrl+shift+5"
]
},
{
"command" : "newTabProfile5",
"keys" :
[
"ctrl+shift+6"
]
},
{
"command" : "newTabProfile6",
"keys" :
[
"ctrl+shift+7"
]
},
{
"command" : "newTabProfile7",
"keys" :
[
"ctrl+shift+8"
]
},
{
"command" : "newTabProfile8",
"keys" :
[
"ctrl+shift+9"
]
},
{
"command" : "nextTab",
"keys" :
[
"ctrl+tab"
]
},
{
"command" : "openSettings",
"keys" :
[
"ctrl+,"
]
},
{
"command" : "prevTab",
"keys" :
[
"ctrl+shift+tab"
]
},
{
"command" : "scrollDown",
"keys" :
[
"ctrl+shift+down"
]
},
{
"command" : "scrollDownPage",
"keys" :
[
"ctrl+shift+pgdn"
]
},
{
"command" : "scrollUp",
"keys" :
[
"ctrl+shift+up"
]
},
{
"command" : "scrollUpPage",
"keys" :
[
"ctrl+shift+pgup"
]
},
{
"command" : "switchToTab0",
"keys" :
[
"alt+1"
]
},
{
"command" : "switchToTab1",
"keys" :
[
"alt+2"
]
},
{
"command" : "switchToTab2",
"keys" :
[
"alt+3"
]
},
{
"command" : "switchToTab3",
"keys" :
[
"alt+4"
]
},
{
"command" : "switchToTab4",
"keys" :
[
"alt+5"
]
},
{
"command" : "switchToTab5",
"keys" :
[
"alt+6"
]
},
{
"command" : "switchToTab6",
"keys" :
[
"alt+7"
]
},
{
"command" : "switchToTab7",
"keys" :
[
"alt+8"
]
},
{
"command" : "switchToTab8",
"keys" :
[
"alt+9"
]
}
],
"requestedTheme" : "system",
"showTabsInTitlebar" : false,
"showTerminalTitleInTitlebar" : true
},
"profiles" :
[
{
"acrylicOpacity" : 0.5,
"background" : "#0C0C0C",
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "wsl.exe -d Ubuntu",
"cursorColor" : "#00FF00",
"cursorShape" : "filledBox",
"fontFace" : "consolas",
"fontSize" : 11,
"guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"historySize" : 9001,
"icon" : "C:/Users/techlog/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/RoamingState/ubuntu.png",
"name" : "ubuntu",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false
},
{
"acrylicOpacity" : 0.5,
"background" : "#0C0C0C",
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "wsl.exe -d Ubuntu -u zeyu",
"cursorColor" : "#00FF00",
"cursorShape" : "filledBox",
"fontFace" : "consolas",
"fontSize" : 11,
"guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44ba}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png",
"name" : "techlog",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false
},
{
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "cmd.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "cmd",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
{
"acrylicOpacity" : 0.5,
"background" : "#012456",
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "powershell.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{2c4de342-38b7-51cf-b940-2309a097f518}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
"name" : "PowerShell",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"useAcrylic" : false
},
{
"acrylicOpacity" : 0.5,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "cmd.exe \"/K\" D:/programfiles/Anaconda3/Scripts/activate.bat python3.6",
"cursorColor" : "#00FF00",
"cursorHeight" : 25,
"cursorShape" : "vintage",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44b0}",
"historySize" : 9001,
"icon" : "D:/programfiles/Anaconda3/Menu/anaconda-navigator.ico",
"name" : "anoconda",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false
},
{
"acrylicOpacity" : 0.5,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "\"C:/Program Files/Git/bin/bash.exe\"",
"cursorColor" : "#00FF00",
"cursorHeight" : 25,
"cursorShape" : "vintage",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44b1}",
"historySize" : 9001,
"icon" : "C:/Users/techlog/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/RoamingState/git-for-windows.ico",
"name" : "git-bash",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false
}
],
"schemes" :
[
{
"background" : "#0C0C0C",
"black" : "#0C0C0C",
"blue" : "#68B4FF",
"brightBlack" : "#767676",
"brightBlue" : "#11B1FF",
"brightCyan" : "#00FFFF",
"brightGreen" : "#16C60C",
"brightPurple" : "#8080C0",
"brightRed" : "#E74856",
"brightWhite" : "#F2F2F2",
"brightYellow" : "#F9F1A5",
"cyan" : "#00BBBB",
"foreground" : "#F2F2F2",
"green" : "#00FF00",
"name" : "Campbell",
"purple" : "#8080C0",
"red" : "#FF0000",
"white" : "#C0C0C0",
"yellow" : "#FFFF00"
},
{
"background" : "#282C34",
"black" : "#282C34",
"blue" : "#61AFEF",
"brightBlack" : "#5A6374",
"brightBlue" : "#61AFEF",
"brightCyan" : "#56B6C2",
"brightGreen" : "#98C379",
"brightPurple" : "#C678DD",
"brightRed" : "#E06C75",
"brightWhite" : "#DCDFE4",
"brightYellow" : "#E5C07B",
"cyan" : "#56B6C2",
"foreground" : "#DCDFE4",
"green" : "#98C379",
"name" : "One Half Dark",
"purple" : "#C678DD",
"red" : "#E06C75",
"white" : "#DCDFE4",
"yellow" : "#E5C07B"
},
{
"background" : "#FAFAFA",
"black" : "#383A42",
"blue" : "#0184BC",
"brightBlack" : "#4F525D",
"brightBlue" : "#61AFEF",
"brightCyan" : "#56B5C1",
"brightGreen" : "#98C379",
"brightPurple" : "#C577DD",
"brightRed" : "#DF6C75",
"brightWhite" : "#FFFFFF",
"brightYellow" : "#E4C07A",
"cyan" : "#0997B3",
"foreground" : "#383A42",
"green" : "#50A14F",
"name" : "One Half Light",
"purple" : "#A626A4",
"red" : "#E45649",
"white" : "#FAFAFA",
"yellow" : "#C18301"
},
{
"background" : "#073642",
"black" : "#073642",
"blue" : "#268BD2",
"brightBlack" : "#002B36",
"brightBlue" : "#839496",
"brightCyan" : "#93A1A1",
"brightGreen" : "#586E75",
"brightPurple" : "#6C71C4",
"brightRed" : "#CB4B16",
"brightWhite" : "#FDF6E3",
"brightYellow" : "#657B83",
"cyan" : "#2AA198",
"foreground" : "#FDF6E3",
"green" : "#859900",
"name" : "Solarized Dark Custom",
"purple" : "#D33682",
"red" : "#D30102",
"white" : "#EEE8D5",
"yellow" : "#B58900"
},
{
"background" : "#073642",
"black" : "#073642",
"blue" : "#268BD2",
"brightBlack" : "#002B36",
"brightBlue" : "#839496",
"brightCyan" : "#93A1A1",
"brightGreen" : "#586E75",
"brightPurple" : "#6C71C4",
"brightRed" : "#CB4B16",
"brightWhite" : "#FDF6E3",
"brightYellow" : "#657B83",
"cyan" : "#2AA198",
"foreground" : "#FDF6E3",
"green" : "#859900",
"name" : "Solarized Dark",
"purple" : "#D33682",
"red" : "#D30102",
"white" : "#EEE8D5",
"yellow" : "#B58900"
},
{
"background" : "#FDF6E3",
"black" : "#073642",
"blue" : "#268BD2",
"brightBlack" : "#002B36",
"brightBlue" : "#839496",
"brightCyan" : "#93A1A1",
"brightGreen" : "#586E75",
"brightPurple" : "#6C71C4",
"brightRed" : "#CB4B16",
"brightWhite" : "#FDF6E3",
"brightYellow" : "#657B83",
"cyan" : "#2AA198",
"foreground" : "#073642",
"green" : "#859900",
"name" : "Solarized Light",
"purple" : "#D33682",
"red" : "#D30102",
"white" : "#EEE8D5",
"yellow" : "#B58900"
}
]
}
官方出品果然非常好用,连日来的使用中,除了极其偶尔的闪退,没有出现其他问题,毕竟是预览版嘛,已经是十分满意了。 与第三方开发的 cmder 相比,目前来看,官方出品的 Windows Terminal 在字体的显示上有着明显的优势,cmder 的中文显示总是感觉有些难以接受,下图展示了 Windows Terminal 中的中文字体,可以看到,还是非常舒服的:
同时,一个简洁的菜单融合了 cmd、wsl、powershell、anaconda、git-bash 等等 shell,可以说使用起来是十分方便了。 可以说,目前预览版已经可以满足主页君的需要,期待冬季将到来的正式版更新又能带来哪些惊喜吧。
目前的版本,标签栏的显示内容尚不支持手动修改,也无法设置标签的最大显示长度。 使用 WSL 时,标签栏会显示当前完整路径,如果进入的路径很深,或是路径中某个或某几个目录名很长,那么就会导致标签变得很长。
但其实标签栏显示的内容只是 shell 实时返回的终端名称,对于 linux shell,我们可以自己定义其返回的终端名称,而不是默认的过长名称:
function title() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}
随后,只要执行:
title wsl-ubuntu
就可以看到标签名称变成了我们指定的:wsl-ubuntu。
但标签不能移动这个问题就无能为力了。
Windows Terminal 中的复制粘贴沿用了 cmd 中使用鼠标右键的方式,windows 环境下通用的 CTRL + C、CTRL + V、CTRL + INSERT、SHIFT + INSERT 等的快捷键组合均没有作用,同时,配置文件中也并没有复制粘贴相关的配置可以使用,这点比较遗憾。 虽然使用鼠标左右键选中、复制、粘贴的组合方式也十分方便,但毕竟改变了长期以来的使用习惯,还是需要适应,而键盘鼠标的不断切换,对操作效率还是有较大影响的。
目前 windows terminal 只能和其他窗口一样支持最小化、最大化等操作,而不能如其他很多 Terminal 一样支持全屏隐藏标题栏、标签栏等的操作。 不过,通过 showTerminalTitleInTitlebar 配置项(原 experimental_showTabsInTitlebar 配置项),可以实现对标题栏的隐藏,最大化后,与全屏的效果大体相近。
虽然很多终端均不支持 lrzsz,但不可否认,支持 lrzsz 以后,确实方便的多。 Windows Terminal 不支持 lrzsz 其实也无可厚非,还是老老实实使用 scp 命令或者 sftp 协议吧。
通过 defaultProfile 配置,我们可以配置默认打开的标签,但目前来看并不支持配置多个,从而每次都只会打开一个默认标签。 事实上,对于程序员来说,支持默认打开多个标签还是能够省事很多的。
页面内查找信息有时是十分有用的,Windows Terminal 目前尚不支持。 解决方案其实也有,那就是在 linux shell 中使用 screen 来开启虚拟终端,在这个虚拟终端中,你可以通过 screen 提供的查找功能进行业内的查找。
我们看到,Windows Terminal 如同一个初生婴儿,虽然有着诸多不足,但其已经实现了从 0 到 1 的闪亮登场,预览版已足以让主页君感到惊喜,微软官方决定要做的事向来能够最终做到极致,显然这需要一定的时间。 当然,很多人说,Terminal 不过是一个壳,并没有改变 cmd 本身并不好用的现实,但这里要说的是,首先,windows 的 cmd 不好用是 shell 的问题,Terminal 并不是 shell,不能用 shell 的问题来责怪 Terminal,但与此同时,powershell 的多个版本迭代,尤其是 5.0 以来,已经完全改变了 cmd 难以使用的窠臼,一个崭新的 windows shell 已经诞生了,同时,wsl 的存在,让 windows 拥抱 linux shell,同样是令人惊喜的。 期待冬季正式版的推出,究竟会有哪些巨变,拭目以待。