深入浅出,遇见Windows Terminal(Windows终端器),体验及美化新一代终端神器

Windows Terminal 简介

Windows Terminal is a new, modern, feature-rich, productive terminal application for command-line users. It includes many of the features most frequently requested by the Windows command-line community including support for tabs, rich text, globalization, configurability, theming & styling, and more.

The Terminal will also need to meet our goals and measures to ensure it remains fast and efficient, and doesn't consume vast amounts of memory or power.

Windows终端是一个面向命令行工具和 shell(如命令提示符、PowerShell 和适用于 Linux 的 Windows 子系统 (WSL))用户的新式终端应用程序。 它的主要功能包括多个选项卡、窗格、Unicode 和 UTF-8 字符支持、GPU 加速文本呈现引擎,还可以用于创建你自己的主题并自定义文本、颜色、背景和快捷键绑定。

Windows Terminal 下载/安装

方式一,如果有Microsoft Store,那就推荐从商店搜索安装

打开商店,搜索关键词Windows Terminal,即可搜到它,安装即可。

方式二,直接进Windows Terminal Github Release 页面,下载安装包

截稿时最新版:Windows Terminal v1.0.1811.0

官方下载页面:https://github.com/microsoft/terminal/releases

方式三,如果有Windows Package Manager(winget)也可以直接命令行安装

winget install --id=Microsoft.WindowsTerminal -e

Windows Terminal 配置

它的配置,是从打开后,那个下拉小三角的设置项进入的,是一个纯Json形式的Setting.json配置文件。

也就是说,我们只要修改这个文件,就等于是修改它的配置了。

在配置中,找到profiles->defaults的节点,把自定义的配置写在里面就行,按Json的节点模式写哈: Key: Value

启用Windows10 Acrylic半透明效果,并且可设置透明度

"useAcrylic" : true,
"acrylicOpacity" : 0.5

启用指定磁盘路径的背景图片,并且可设置图片透明度

"backgroundImage" : "D:\\xxxxxxxxx\\wallhaven-59448.jpg",
"backgroundImageOpacity": 1

官方详细的配置文档

玩转 Windows Terminal

添加到右键快捷菜单

在记事本/VSC中新建文本

Windows Registry Editor Version 5.00
 ​
 [HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
 @="Windows Terminal here"
 "Icon"=".../xxxxxxxx/terminal.ico"
 ​
 [HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
 @="C:\\Users\\UserName\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

以上所有路径都要用两个\\来表示。

保存为xxxxxxx.reg,然后运行即可。

在Windows Terminal中设置Powerline

安装Posh-Git、Oh-My-Posh

Posh-Git 将Git状态信息添加到提示,并为Git命令、参数、远程和分支名称添加tab自动补全。Oh-My-Posh为PowerShell提示符提供主题功能。

执行以下命令行:

Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck

然后需要修改PowerShell配置文件。

如果有配置直接执行:

notepad $PROFILE

如果没有配置,先执行下面命令,再操作上面的

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }

生成之后,这个文件大概的位置在C:\Users\xxxxxxxxxx\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

编辑这个文件,追加以下命令行:

老版本V2

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox

新版本V3

Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt paradox

Posh-Git将Git状态信息添加到提示,并为Git命令、参数、远程和分支名称添加tab自动补全。

Oh-My-Posh为PowerShell提示符提供主题功能。

如果你是从老版本升级,可以走命令:

Update-Module -Name oh-my-posh -Scope CurrentUser

如果卸载,可以走命令:

Uninstall-Module oh-my-posh

如果查看所有的主题,可以走命令:

Get-PoshThemes

从V2=>V3变化:https://ohmyposh.dev/docs/upgrading/

接下来,重启Windows Terminal可能会提示没有权限执行ps脚本,开始菜单右键,在Windows PowerShell 管理员模式执行下面命令即可:

set-executionpolicy remotesigned

再次重启Windows Terminal即可恢复正常。

安装Cascadia Code编程字体,解决乱符号问题

经过前面折腾,我们发现命令行有一些乱码,这是因为有些符号是存在字体里面的,我们下载安装一个微软出品的字体,叫Cascadia Code

官网下载地址:CascadiaCode-2106.17.zip From Github Release Page

Cascadia Code 项目主页

下载之后,解压,把ttf文件夹里面的都安装一遍吧,基本上就够了。

同时去Windows Terminal的Setting中给PowerShell加一个fontFace配置。

"fontFace": "Cascadia Code PL"

image

好了,再次重启Windows Terminal,你将看到你梦想的效果了!

试试git模式,哈哈,效果可以亮虾你。

开启新终端欢迎词界面

找到C:\Users\xxxxxxxxxxxx\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1这个文件,编辑它。

准备在它头部插入点啥。

好啦,来这个网址输入你喜欢的昵称,http://patorjk.com/software/taag/#p=testall&f=Graffiti&t=TaylorShi

点击Test All,选择你喜欢的风格。

点击你中意的一项的Select & Copy,然后粘贴到上面那个文件的头部,保存!

全部内容参考如下:

clear
$hello="
 .----------------.  .----------------.  .----------------.  .----------------.  .----------------.  .----------------. 
| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
| |  _________   | || |      __      | || |  ____  ____  | || |   _____      | || |     ____     | || |  _______     | |
| | |  _   _  |  | || |     /  \     | || | |_  _||_  _| | || |  |_   _|     | || |   .'    `.   | || | |_   __ \    | |
| | |_/ | | \_|  | || |    / /\ \    | || |   \ \  / /   | || |    | |       | || |  /  .--.  \  | || |   | |__) |   | |
| |     | |      | || |   / ____ \   | || |    \ \/ /    | || |    | |   _   | || |  | |    | |  | || |   |  __ /    | |
| |    _| |_     | || | _/ /    \ \_ | || |    _|  |_    | || |   _| |__/ |  | || |  \  `--'  /  | || |  _| |  \ \_  | |
| |   |_____|    | || ||____|  |____|| || |   |______|   | || |  |________|  | || |   `.____.'   | || | |____| |___| | |
| |              | || |              | || |              | || |              | || |              | || |              | |
| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
 '----------------'  '----------------'  '----------------'  '----------------'  '----------------'  '----------------' 
"
$hello
"Welcome back, Taylor"
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt paradox

打开一个新的Windows Terminal标签,就可以看到效果。

设置Visual Studio Code字体

操作完前面的流程之后,我们有时候在Visual Studio Code中打开可能会遇到乱码问题,那么我们只需要打开VSC的设置界面,找到常用设置中,设置Font Family即可:

Cascadia Code PL,

image

参考

posted @ 2020-07-08 10:08  TaylorShi  阅读(7449)  评论(0编辑  收藏  举报