手把手教你美化微软的新终端Windows Terminal
1. 前言
微软的新终端Windows Terminal终于发布正式版了。这个终端诞生以来就大获好评,对于使用Windows进行开发的小伙伴来说又有了新的玩具了。先来看看官方的介绍视频吧。
接着胖哥教大家如何去美化这个终端,把它打造成时尚的开发利器。
2. 安装
安装非常简单,通过Microsoft Store可以轻松安装Windows Terminal。
3. 安装美化主题
打开PowerShell安装Oh-My-Posh[1]和Posh-Git[2]
Set-ExecutionPolicy Bypass
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Posh-Git将Git状态信息添加到提示,并为Git命令、参数、远程和分支名称添加 tab 自动补全。Oh-My-Posh为PowerShell提示符提供主题功能。
如果使用的是PowerShell Core,请安装PSReadline:
Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck
然后PowerShell命令行执行:
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE
会打开如下记事本,将下面的代码配置到记事本中保存:
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
当然你可以在命令行中执行 Get-Theme
列出所有的样式:
然后使用Set-Theme 名称
来预览你想要的风格,然后替换上面的记事本对应的样式名称即可。
4. 安装 Powerline 字体
Powerline提供自定义的命令提示符体验,提供Git状态颜色编码和提示符,不然很多符号都是乱码。
推荐到我的Git仓库下载,地址为https://gitee.com/felord/fonts,安装方法参考README,非常简单。
5. 自定义配置
按照上图打开配置是一个json文件,这里我贴一下我的配置,你抄就是了:
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings
// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,
// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,
// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles": {
"defaults": {
// Put settings here that you want to apply to all profiles.
"colorScheme": "Banana Blueberry",
"background": "#191323", //背景颜色,PS默认为蓝色
"closeOnExit": true, //关闭窗口的时候退出所有挂载的程序
"commandline": "powershell.exe", //此处终端打开PS
"cursorColor": "#FFFFFF", //光标颜色
"cursorShape": "bar", //光标形状(默认为bar,即条状)
"fontFace": "DejaVu Sans Mono for Powerline",
"fontSize": 12,
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", //唯一标识符,随机生成
"historySize": 9001, //缓存大小
"icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png", //图标
"name": "PowerShell", //在下拉菜单里显示的名称
"tabTitle": "PowerShell", //在选项卡上显示的名称
"padding": "0, 0, 0, 0", //内容的边框距,默认填充全部空间
"snapOnInput": true, //输入的时候自动滚动到输入位置
"startingDirectory": "%USERPROFILE%" //初始工作目录,默认为用户目录
},
"list": [
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
}
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [
{
"name": "Monokai Night",
"background": "#1f1f1f",
"foreground": "#f8f8f8",
"black": "#1f1f1f",
"blue": "#6699df",
"cyan": "#e69f66",
"green": "#a6e22e",
"purple": "#ae81ff",
"red": "#f92672",
"white": "#f8f8f2",
"yellow": "#e6db74",
"brightBlack": "#75715e",
"brightBlue": "#66d9ef",
"brightCyan": "#e69f66",
"brightGreen": "#a6e22e",
"brightPurple": "#ae81ff",
"brightRed": "#f92672",
"brightWhite": "#f8f8f2",
"brightYellow": "#e6db74"
},
{
"name": "Banana Blueberry",
"black": "#17141f",
"red": "#ff6b7f",
"green": "#00bd9c",
"yellow": "#e6c62f",
"blue": "#22e8df",
"purple": "#dc396a",
"cyan": "#56b6c2",
"white": "#f1f1f1",
"brightBlack": "#495162",
"brightRed": "#fe9ea1",
"brightGreen": "#98c379",
"brightYellow": "#f9e46b",
"brightBlue": "#91fff4",
"brightPurple": "#da70d6",
"brightCyan": "#bcf3ff",
"brightWhite": "#ffffff",
"background": "#191323",
"foreground": "#cccccc"
}
],
// Add custom keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about keybindings, visit https://aka.ms/terminal-keybindings
"keybindings": [
// 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"
},
// 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"
}
]
}
如果你想修改字体找到fontFace
配置Powerline字体;如果你要修改配色方案,找到schemes
数组后将配色方案添加进去即可,激活参考上面的配置将 schemes[i].name
的值填写到profiles.defaults.colorScheme
保存重启终端即可。
这里推荐一个Windows Terminal配色方案的Github项目Windows Terminal Themes[3]
其它什么透明、毛玻璃、背景图的操作,网上有很多教程,过于简单这里就不提了。更多的配置可参考Windows Terminal 官方文档[4]
6. 添加 Windows Terminal 到右键菜单
将Windows Terminal添加到右键菜单也是刚需啊,会让我们方便很多。这里告诉你一个最简单的方法,下载一个脚本右键执行安装就行了。脚本可以通过公众号:码农小胖哥 回复 wint 即可。
文中引用
Oh-My-Posh: https://github.com/JanDeDobbeleer/oh-my-posh
[2]Posh-Git: https://github.com/dahlbyk/posh-git
[3]Windows Terminal Themes: https://atomcorp.github.io/themes
[4]Windows Terminal官方文档: https://docs.microsoft.com/zh-cn/windows/terminal/
往期推荐:
2020-06-28
2020-06-26
2020-06-25
更多精彩尽在阅读原文,如果文章对您有用请点个再看和转发让更多人看到。