前言
Windows 终端是一个面向命令行工具和 shell(如命令提示符、PowerShell 和适用于 Linux 的 Windows 子系统 (WSL))用户的新式终端应用程序。 它的主要功能包括多个选项卡、窗格、Unicode 和 UTF-8 字符支持、GPU 加速文本呈现引擎,还可以用于创建你自己的主题并自定义文本、颜色、背景和快捷键绑定。
1. 安装
从 windows store中安装,搜索terminal 有两个,一个microsoft terminal一个windows terminal preview , 选择后者。
如果你无法访问 Microsoft Store,GitHub 发布页上发布有内部版本。 如果从 GitHub 安装,终端将不会自动更新为新版本。
2. 配置参考
可参考我的配置:
// This file was initially generated by Windows Terminal Preview 1.2.2022.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": {
// Put settings here that you want to apply to all profiles.
"fontFace": "Cascadia Code",
"fontSize": 10,
"useAcrylic": true, //使用背景透明
"acrylicOpacity": 0.8, //背景透明度
"launchMode": "default", //启动大小 default , maximized , fullscreen
"initialPosition": "800,#" //启动位置
},
"list": [
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"hidden": false,
"startingDirectory": null //默认值:"%USERPROFILE%",通过地址栏启动,输入 wt 即可打开Windows terminal (类似cmd)
},
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"startingDirectory": null,
"fontFace": "Cascadia Code PL",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": true,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b7}",
"hidden": false,
"name": "git bash",
"icon": "D:\\Program Files\\Git\\favicon.ico",
"commandline": "D:\\Program Files\\Git\\bin\\bash.exe"
}
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [],
// 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"
}
]
}
效果图:
3. 添加git-bash 命令
在list中添加一个对象
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b7}",
"hidden": false,
"name": "git bash",
"icon": "D:\\Program Files\\Git\\favicon.ico",
"commandline": "D:\\Program Files\\Git\\bin\\bash.exe"
}
其中guid可用工具生成, icon从官网下载(打开git-bash官网后,在控制台网络中可找到favicon.ico),放到适当位置,引用其位置即可。
commandline
填写已安装的git下的bash.exe路径
4. 在powershell中使用git并带有命令行自动补全和漂亮的文本[可选]
[可选内容,喜欢折腾的用户随意]
参考:https://docs.microsoft.com/zh-cn/windows/terminal/tutorials/powerline-setup
下载字体并安装:Cascadia Mono PL , 字体下载:CascadiaPL.ttf, 下载后直接双击字体即可安装。
使用 PowerShell,安装 Posh-Git 和 Oh-My-Posh:
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
注意此处安装可能会失败,需要kexuejishu上网
- 使用powershell 启动自动加载配置文件
echo $profile
Test-Path $profile
New-Item -Path $profile -Type File –Force
使用echo $profile
检查.ps1文件是否存在,Test-Path $profile
进一步测试是否存在,若不存在则用命令新建一个New-Item -Path $profile -Type File –Force
使用文本编辑器打开该 PowerShell 配置文件,该脚本在每次启动 PowerShell 时运行。 详细了解 PowerShell 配置文件。
在 PowerShell 配置文件中,将以下内容添加到文件的末尾:
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
现在,每个新实例启动时都会导入 Posh-Git 和 Oh-My-Posh,然后从 Oh-My-Posh 设置 Paradox 主题。 Oh-My-Posh 附带了若干内置主题。
效果如下:
- 注意: 如果启动powershell时报错如下:
. : 无法加载文件 C:\Users\wweim\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,因为在此系统上禁止运行脚
本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\wweim\Documents\WindowsPowerShell\Microsoft.PowerShell_pr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
则可根据https:/go.microsoft.com/fwlink/?LinkID=135170中的提示进行设置, 简单的方式可这样操作:
使用管理员权限打开powershell
Get-ExecutionPolicy
# 如果是Restricted, 则代表不能使用本地加载ps1
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# 设置本地用户执行策略为 RemoteSigned
完成, 重新打开terminal后进入powershell可发现已经可以加载ps1文件
5. 将本地cmd命令默认使用windows terminal打开
快捷键win+r
后在打开的运行窗口输入cmd
打开cmd窗口后在窗口头部右键选择属性打开属性对话框,然后选择终端,在默认终端应用程序中选择Windows Terminal即可,下次打开cmd时自动使用Windows Terminal终端打开
或者在打开的Windows Terminal终端中选择设置
6. Windows Terminal启动快捷方式
方法1: win+s
中输入wt
即可启动Windows Terminal
方法2: win+r
中输入wt
即可启动Windows Terminal
方法3: 在文件夹路径上输入wt
,此命令根目录为默认目录
方法4: (推荐)在文件夹路径上输入'cmd',此时命令根目录为当前目录
方法5: (推荐)大多数编辑器(如:vs,vscode,webstorm,idea等等)都自带终端,打开终端后直接输入start cmd
也可打开终端, 而且终端根目录也是当前自带终端的根目录. 方便执行带有当前路径的命令.
总结
本文从安装到设置,再到默认切换终端,最后快捷的启动方式,简单的带你进入了Windows Terminal的世界, 从此一款高效、美观、现代的命令行工具伴随着我们的日常开发😊
本文作者:wwmin
微信公众号: DotNet技术说
本文链接:https://www.jianshu.com/p/faeb78aed400
版权声明:转载请注明出处!
声援博主:如果您觉得文章对您有帮助,关注点赞, 您的鼓励是博主的最大动力!