前言
这段时间呢,我一直是用cmder或者windows ISE的,但是这两货的优点很多,缺点也不少,比如说:启动慢(ISE一个启动都要2s,我打命令都打完了他还没启动完),颜值低(ISE不支持更改外观,cmder可以更改的地方很少。)于是,我到一些群里面去问:“有没有大佬,求一个windows下的Shell客户端”,回答的答案很多:“cmder,Xshell,WSL(Windows子Linux),Windows terminal”,当我看到windows terminal的时候,我脑中浮现出一个奇怪的问题:“可以魔改吗?”,于是我发出了这个问题,得到的结果是:“可以”,我那颗折腾的心变得Exciting了起来!
下载
怎么下载呢?
你可以在这个链接下载,或者直接到Windows Store里面搜索”windows terminal”下载
阐述
Windows 终端是一个面向命令行工具和 shell(如命令提示符、PowerShell 和适用于 Linux 的 Windows 子系统 (WSL))用户的新式终端应用程序。 它的主要功能包括多个选项卡、窗格、Unicode 和 UTF-8 字符支持、GPU 加速文本呈现引擎,你还可用它来创建你自己的主题并自定义文本、颜色、背景和快捷方式。
支持多种命令行应用程序的多个配置文件
任何具有命令行接口的应用程序都可以在 Windows 终端中运行。 这包括从 PowerShell 和命令提示符到 Azure Cloud Shell 和任何 WSL 分发(如 Ubuntu 或 Oh-My-Zsh)的所有应用程序。
自定义方案和配置
可以将 Windows 终端配置为具有多种配色方案和设置。 若要了解如何创建自己的配色方案,请访问配色方案页面。 还可以在自定义终端库中查找自定义终端配置。
自定义操作
可在 Windows 终端中使用多种自定义命令,获得更加自然的体验。 如果不喜欢特定的键盘快捷方式,可以将其更改为你喜欢的方式。
例如,若要复制命令行中的文本,默认的快捷方式为 ctrl+shift+c
。 你可以将其更改为 ctrl+1
或你喜欢的其他方式。 要打开新的选项卡,默认快捷方式是 ctrl+t
,但你可能想要将其更改为 ctrl+2
。 用于在打开的选项卡之间进行切换的默认快捷方式是 ctrl+tab
,可以将这个快捷方式更改为 ctrl+-
并改为用于创建新选项卡。
可在操作页面上了解如何自定义快捷方式。
Unicode 和 UTF-8 字符支持
Windows 终端可以显示 Unicode 和 UTF-8 字符,如各种语言的表情符号和字符。
GPU 加速文本呈现
Windows 终端使用 GPU 来呈现其文本,从而提供比默认 Windows 命令行体验更好的性能。
背景图像支持
可以在 Windows 终端窗口中显示背景图像和 gif。 有关如何向配置文件添加背景图像的信息,请参阅配置文件设置页。
命令行参数
可以使用命令行参数将 Windows 终端设置为在特定配置中启动。 可以指定要在新选项卡中打开哪个配置文件、应选择哪个文件夹目录,指定使用拆分窗口窗格打开终端,并指定选择应专注于哪个选项卡。
例如,若要使用三个窗格从 PowerShell 打开 Windows 终端(左窗格运行命令提示符配置文件,右窗格拆分为两个,一个用于 PowerShell,另一个用于运行 WSL 的默认配置文件),请输入:
wt -p "Command Prompt" `; split-pane -p "Windows PowerShell" `; split-pane -H wsl.exe
更新
微软宣布从 2020 年 7 月开始,Windows Terminal 每月都会获得一次更新。
这是一个开源项目,微软欢迎全球开发者社区参与。如要参与,请访问:GitHub | Windows Terminal
此外,微软宣布正式启动预览项目 Windows Terminal Preview,开发者还可以从微软官方文档页面获取相关支持:Windows Terminal | Microsoft Docs
美化
powershell美化
在美化windows terminal之前,我们先来美化powershell这个傻大蓝。
在命令行依次输入
# 安装 PSReadline 包,让命令行更好用
Install-Module -Nane PSReadLine -AllowPrerelease -Force
# 安装 posh-git 包,优化Git(bash)
Install-Module posh-git -Scope CurrentUser
# 划重点!安装 oh-my-posh 包,美化傻大蓝(poweshell)
Install-Module oh-my-posh -Scope CurrentUser
# 允许脚本本地运行 & 安装 Scope 包管理器
set-executionpolicy remotesigned -scope currentuser
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
没网络的时候~
⚡ ChenShang ~ ❯❯❯ if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force } # 检验是否有 $PROFILE,没有就创建一个
⚡ ChenShang ~ ❯❯❯ notepad $PROFILE # 记事本打开 $PROFILE
⚡ ChenShang ~ ❯❯❯ code $PROFILE # 记事本打开 $PROFILE
⚡ ChenShang ~ ❯❯❯ code $PROFILE # 记事本打开 $PROFILE
⚡ ChenShang ~ ❯❯❯ code $PROFILE # 记事本打开 $PROFILE
⚡ ChenShang ~ ❯❯❯ # 安装 PSReadline 包,让命令行更好用
⚡ ChenShang ~ ❯❯❯ Install-Module -Nane PSReadLine -AllowPrerelease -Force
Install-Module : 找不到与参数名称“Nane”匹配的参数。
所在位置 行:1 字符: 16
+ Install-Module -Nane PSReadLine -AllowPrerelease -Force
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Install-Module],ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Install-Module
⨯ ⚡ ChenShang ~ ❯❯❯ # 安装 posh-git 包,优化Git(bash)
⚡ ChenShang ~ ❯❯❯ Install-Module posh-git -Scope CurrentUser
警告: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Install-Package : 找不到与指定的搜索条件和程序包名称“posh-git”匹配的项目。请尝试使用 Get-PSRepository 查看所有可用的注册程序包源。
所在位置 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 字符: 21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
⨯ ⚡ ChenShang ~ ❯❯❯ # 划重点!安装 oh-my-posh 包,美化傻大蓝(poweshell)
⚡ ChenShang ~ ❯❯❯ Install-Module oh-my-posh -Scope CurrentUser
警告: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Install-Package : 找不到与指定的搜索条件和程序包名称“oh-my-posh”匹配的项目。请尝试使用 Get-PSRepository 查看所有可用的注册程序包源。
所在位置 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 字符: 21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
⨯ ⚡ ChenShang ~ ❯❯❯ # 允许脚本本地运行 & 安装 Scope 包管理器
⚡ ChenShang ~ ❯❯❯ set-executionpolicy remotesigned -scope currentuser
⚡ ChenShang ~ ❯❯❯ iex (new-object net.webclient).downloadstring('https://get.scoop.sh')^C
⚡ ChenShang ~ ❯❯❯
安装完oh-my-posh后
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force } # 检验是否有 $PROFILE,没有就创建一个
notepad $PROFILE # 记事本打开 $PROFILE
在记事本里面输入以下:
Import-Module posh-git # 导入posh-git的模块
Import-Module oh-my-posh # 导入oh-my-posh的模块
Set-Theme Sorin # 将样式设定为Sorin
美化Windows terminal
所要用到的代码如下
"backgroundImage": "https://upimage.alexhchu.com/2021/01/01/378b347c10053.jpg", // bg url
"backgroundImageOpacity": 0.5,
"closeOnExit": true,
"color": "#FFFFFF",
"cursorShape": "bar",
"icon": "E://shell//PS.png",
"padding": "0, 0, 0, 0",
"snapOnInput": true,
"startingDirectory": "%USERPROFILE%",
"tabTitle": "Windows-10-Shell",
"useAcrylic": true,
"profiles":
{
"defaults":
{
"fontFace" : "JetBrains Mono",
"cursorColor": "#9e9e9e",
"fontSize" : 13 // 字体大小,
// Put settings here that you want to apply to all profiles.
},
加在这里的话只需要写一次代码,然后所有的全部都一个样(除了标题)
或者放这:
"list":
[
{
// Make changes here to the powershell.exe profile.
// powershell
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"backgroundImage": "https://upimage.alexhchu.com/2021/01/01/378b347c10053.jpg", // bg url
"backgroundImageOpacity": 0.5,
"closeOnExit": true,
"color": "#FFFFFF",
"cursorShape": "bar",
"icon": "E://shell//PS.png",
"padding": "0, 0, 0, 0",
"snapOnInput": true,
"startingDirectory": "%USERPROFILE%",
"tabTitle": "Windows-10-Shell",
"useAcrylic": true,
"hidden": false
},
但是放在这里的话就要每一个list都写一次刚才的代码了。很麻烦….但是很有效
我的个人主题配置文件
// This file was initially generated by Windows Terminal 1.4.3243.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$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":
{
"fontFace" : "JetBrains Mono",
"cursorColor": "#9e9e9e",
"fontSize" : 13 // 字体大小,
// Put settings here that you want to apply to all profiles.
},
"list":
[
{
// Make changes here to the powershell.exe profile.
// powershell
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"backgroundImage": "https://upimage.alexhchu.com/2021/01/01/378b347c10053.jpg", // bg url
"backgroundImageOpacity": 0.5,
"closeOnExit": true,
"color": "#FFFFFF",
"cursorShape": "bar",
"icon": "E://shell//PS.png",
"padding": "0, 0, 0, 0",
"snapOnInput": true,
"startingDirectory": "%USERPROFILE%",
"tabTitle": "Windows-10-Shell",
"useAcrylic": true,
"hidden": false
},
{
// Make changes here to the powershell.exe profile.
// powershell
"guid": "{1c4de342-38b7-51cf-b940-2309a097f584}",
"name": "Git-Bash",
"commandline": "E:\\Git\\bin\\bash.exe",
"backgroundImage": "https://www.cxyxiaowu.com/wp-content/uploads/2020/06/1591422723-a39d058bfb6e1cf.png", // bg url
"backgroundImageOpacity": 0.9,
"closeOnExit": true,
"color": "#FFFFFF",
"cursorShape": "bar",
"icon": "E://shell//git.png",
"padding": "10, 10, 10, 10",
"snapOnInput": true,
"startingDirectory": "%USERPROFILE%",
"tabTitle": "Git-Bash",
"useAcrylic": true,
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
// cmd
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"acrylicOpacity" : 0.75,
"backgroundImage" : "https://upimage.alexhchu.com/2021/01/01/f9ced42a624e7.jpg", // 图片地址
"backgroundImageOpacity" : 0.9,
"closeOnExit" : true,
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"icon" : "E://shell//cmd.png",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"tabTitle" : "default",
"useAcrylic" : true, //毛玻璃 关掉
"hidden": false
},
{
// -user cloud
"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": [],
// Add custom actions and keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
"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" },
// 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" }
]
}
建议在我的基础上加以修正,不要直接拿我的。
后记
那个什么,这篇文章写的不怎么好,我没有什么文笔,写技术博客的时候很难下手,写这篇文章的原因是因为有人接的我的Windows terminal好…看…(怎么这么生疏)来简单讲讲流程和原理:
先下载,那怎么下载呢?
安装需要的模块
# 安装 PSReadline 包,让命令行更好用
Install-Module -Nane PSReadLine -AllowPrerelease -Force
# 安装 posh-git 包,优化Git(bash)
Install-Module posh-git -Scope CurrentUser
# 划重点!安装 oh-my-posh 包,美化傻大蓝(poweshell)
Install-Module oh-my-posh -Scope CurrentUser
# 允许脚本本地运行 & 安装 Scope 包管理器
set-executionpolicy remotesigned -scope currentuser
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
建议在有网络的环境下下载
- 配置ho-my-posh到Poweshell
检验PS(powershell)的配置文件有没有呆在它应该呆在的地方,如果没有,那就给它造个兄弟,在他的兄弟的身体里面写下如下
Import-Module posh-git # 导入posh-git的模块
Import-Module oh-my-posh # 导入oh-my-posh的模块
Set-Theme Sorin # 将样式设定为Sorin
- 配Json,在标签旁边的“+”的设置,或者直接
Ctrl+,
我的setting.json:
// This file was initially generated by Windows Terminal 1.4.3243.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$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":
{
"fontFace" : "JetBrains Mono",
"cursorColor": "#9e9e9e",
"fontSize" : 13 // 字体大小,
// Put settings here that you want to apply to all profiles.
},
"list":
[
{
// Make changes here to the powershell.exe profile.
// powershell
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"backgroundImage": "https://upimage.alexhchu.com/2021/01/01/378b347c10053.jpg", // bg url
"backgroundImageOpacity": 0.5,
"closeOnExit": true,
"color": "#FFFFFF",
"cursorShape": "bar",
"icon": "E://shell//PS.png",
"padding": "0, 0, 0, 0",
"snapOnInput": true,
"startingDirectory": "%USERPROFILE%",
"tabTitle": "Windows-10-Shell",
"useAcrylic": true,
"hidden": false
},
{
// Make changes here to the powershell.exe profile.
// powershell
"guid": "{1c4de342-38b7-51cf-b940-2309a097f584}",
"name": "Git-Bash",
"commandline": "E:\\Git\\bin\\bash.exe",
"backgroundImage": "https://www.cxyxiaowu.com/wp-content/uploads/2020/06/1591422723-a39d058bfb6e1cf.png", // bg url
"backgroundImageOpacity": 0.9,
"closeOnExit": true,
"color": "#FFFFFF",
"cursorShape": "bar",
"icon": "E://shell//git.png",
"padding": "10, 10, 10, 10",
"snapOnInput": true,
"startingDirectory": "%USERPROFILE%",
"tabTitle": "Git-Bash",
"useAcrylic": true,
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
// cmd
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"acrylicOpacity" : 0.75,
"backgroundImage" : "https://upimage.alexhchu.com/2021/01/01/f9ced42a624e7.jpg", // 图片地址
"backgroundImageOpacity" : 0.9,
"closeOnExit" : true,
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"icon" : "E://shell//cmd.png",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"tabTitle" : "default",
"useAcrylic" : true, //毛玻璃 关掉
"hidden": false
},
{
// -user cloud
"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": [],
// Add custom actions and keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
"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" },
// 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" }
]
}
本人用的是Sorin的主题,不知道各位喜欢什么,在百度上面都有的。
也可以用
Set-Theme Theme-Name # 预览主题
后记-2
平台
这个Windows Terminal是不跨平台的,只在Windows下才有。如果是MAC的,我推荐一个命令行,你或许认得它,它的名字是——Item2。
WSL
WSL是指Windows Linux。Windows下的Linux子系统,Windows terminal也是可以兼容的。至于怎么配置,我下一篇再写…
完成时间
2021/1/2/0:04:44