手把手教你美化微软的新终端Windows Terminal

黄沙百战穿金甲,不破楼兰终不还。这篇文章主要讲述手把手教你美化微软的新终端Windows Terminal相关的知识,希望能为你提供帮助。


1. 前言微软的新终端?Windows Terminal?终于发布正式版了。这个终端诞生以来就大获好评,对于使用?Windows?进行开发的小伙伴来说又有了新的玩具了。先来看看官方的介绍视频吧。
接着胖哥教大家如何去美化这个终端,把它打造成时尚的开发利器。
2. 安装安装非常简单,通过?Microsoft Store?可以轻松安装?Windows Terminal?。

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


配置PowerShell
当然你可以在命令行中执行 ??Get-Theme?? 列出所有的样式:

列出所有样式
然后使用??Set-Theme 名称??来预览你想要的风格,然后替换上面的记事本对应的样式名称即可。
4. 安装 Powerline 字体?Powerline?提供自定义的命令提示符体验,提供?Git?状态颜色编码和提示符,不然很多符号都是乱码。

Windows 终端 Powerline PowerShell
推荐到我的?Git?仓库下载,地址为https://gitee.com/felord/fonts,安装方法参考?README?,非常简单。
5. 自定义配置
打开Windows Terminal 配置
按照上图打开配置是一个?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 panes 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 Themes
其它什么透明、毛玻璃、背景图的操作,网上有很多教程,过于简单这里就不提了。更多的配置可参考Windows Terminal 官方文档?[4]?
6. 添加 Windows Terminal 到右键菜单
【手把手教你美化微软的新终端Windows Terminal】Windows Terminal

    推荐阅读