windows终端终端
In this article, we’ll explore Windows Terminal, the ideal accompaniment to WSL2. It’s fast, configurable, looks great, and offers all the benefits of both Windows and Linux development.
在本文中,我们将探讨Windows终端,它是WSL2的理想伴侣 。它快速,可配置,外观精美,并提供Windows和Linux开发的所有优势。
Windows has fully embraced Linux, and WSL2 makes it a seamless pleasure.
Windows已完全采用Linux,而WSL2使其成为一种无缝的乐趣。
Your distro’s terminal can be accessed by:
您可以通过以下方式访问发行版的终端:
clicking its Start menu icon单击其开始菜单图标
enteringwsl
orbash
at a Powershell or command prompt
在Powershell或命令提示符下输入wsl
或bash
using a third-party terminal option such as Cmder, ConEmu, and Hyper with a profile which launches%windir%\system32\bash.exe ~
使用第三方终端选项(例如Cmder , ConEmu和Hyper)与启动%windir%\system32\bash.exe ~
的配置文件%windir%\system32\bash.exe ~
setting Linux as the default shell in VS Code by pressingCtrl+Shift+Pand typing/choosingTerminal: Select Default Shell, and selectingWSL Bash.
通过按Ctrl+Shift+P并键入/选择Terminal来将Linux设置为VS Code中的默认Shell:选择Default Shell,然后选择WSL Bash。
Windows Terminal offers a further choice, but you won’t regret installing it. The new application features:
Windows Terminal提供了进一步的选择,但是您不会后悔安装它。 新的应用程序功能:
support for WSL2, SSH, Powershell, cmd and other command lines支持WSL2,SSH,Powershell,cmd和其他命令行 multiple tabs and split panes多个选项卡和拆分窗格 configurable themes, background images, and transparency effects可配置的主题,背景图像和透明效果 a search box搜索框 custom key bindings自定义键绑定 GPU accelerated text renderingGPU加速文字渲染
a great-looking new font, Cascadia Code
美观的新字体Cascadia Code
low resource usage (typically 10MB per tab)资源使用率低(每个选项卡通常10MB) auto-updating (if using the Microsoft Store)自动更新(如果使用Microsoft Store)
good documentation
好的文件
and it’s open source!
而且它是开源的 !
如何安装Windows Terminal (How to Install Windows Terminal)
The easiest way to install Windows Terminal is via the Microsoft Store:
安装Windows Terminal的最简单方法是通过Microsoft Store:
ms-windows-store://pdp/?ProductId=9n0dx20hk701
If this link fails, try opening the Microsoft Store in your browser or launching theMicrosoft Storeapp from the Windows Start menu and searching for “Terminal”.
如果此链接失败,请尝试在浏览器中打开Microsoft Store或从Windows“开始”菜单启动Microsoft Store应用程序,然后搜索“终端”。
Note: be careful not to select the earlier “Windows Terminal Preview” application.
注意:注意不要选择早期的“ Windows Terminal Preview”应用程序。
HitGetand wait a few seconds for installation to complete.
点击获取并等待几秒钟以完成安装。
If you don’t have access to the Store, you can download the latest release from GitHub.
如果您无权访问商店,则可以从GitHub下载最新版本 。
TheWindows Terminalapp icon is now available in the Windows Start menu. For easier access, right-click the icon and choosePin to StartorMore, followed byPin to taskbar.
Windows终端应用程序图标现在在Windows“开始”菜单中可用。 为了更容易访问,请右键单击该图标,然后选择“固定到开始”或“更多”,然后选择“固定到任务栏”。
Windows Terminal入门 (Getting Started with Windows Terminal)
When it’s first run, Windows Terminal starts with Powershell as the default profile. A drop-down menu is available to launch other tabs and access the settings:
首次运行时,Windows Terminal以Powershell作为默认配置文件启动。 下拉菜单可用于启动其他选项卡并访问设置 :
Terminal automatically generates profiles for all WSL distros and Windows shells you have installed, although it’s possible to disable generation in the global settings.
尽管可以在全局设置中禁用生成,但是Terminal会自动为您安装的所有WSL发行版和Windows Shell生成配置文件。
管理标签和窗格 (Managing Tabs and Panes)
Open a new tab for the default profile by clicking the+icon orCtrl+Shift+T. To open a tab for a different profile, choose it from the drop-down menu or pressCtrl+Shift+N, whereNis the profile’s number.
通过单击+图标或Ctrl+Shift+T打开默认配置文件的新标签。 要打开其他配置文件的标签,请从下拉菜单中选择该标签,或按Ctrl+Shift+N,其中N是配置文件的编号。
PressAlt+Shift+Dto duplicate and split the pane. The active pane is split in two along the longest axis each time it is used:
按Alt+Shift+D复制并拆分窗格。 每次使用时,活动窗格都会沿最长轴分成两部分:
To force creation of a:
强制创建:
vertical pane, pressAlt+Shift++, or
垂直窗格中,按Alt+Shift++或
horizontal pane, pressAlt+Shift+-
水平窗格,按Alt+Shift+-
To open another profile in a new pane, hold down theAltkey when choosing it from the drop-down menu.
要在新窗格中打开另一个配置文件,请在从下拉菜单中选择时按住Alt键。
Hold downAltand use the cursor keys to switch between active panes from the keyboard. The size of a pane can be adjusted by holdingAlt+Shiftand using the cursor keys to resize accordingly.
按住Alt键,然后使用光标键在键盘上的活动窗格之间切换。 可以通过按住Alt+Shift并使用光标键相应地调整大小来调整窗格的大小。
Tabs can be renamed by double-clicking the text. You can also change the name or color by right-clicking the tab and choosing a menu option:
可以通过双击文本来重命名选项卡。 您还可以通过右键单击标签并选择菜单选项来更改名称或颜色:
This only affects the current tab; it doesn’t permanently change the profile.
这只会影响当前标签页; 它不会永久更改配置文件。
To close the active pane or tab, pressAlt+Shift+Wor enter the terminal’s standard exit command (usuallyexit).
要关闭活动的窗格或选项卡,请按Alt+Shift+W或输入终端的标准退出命令(通常是exit)。
字体大小 (Text size)
The text size of the active terminal can be resized withCtrl++andCtrl+-. Alternatively, hold downCtrland scroll the mouse wheel.
活动终端的文本大小可以使用Ctrl++和Ctrl+-调整大小。 或者,按住Ctrl并滚动鼠标滚轮。
卷动 (Scrolling)
Use the scroll bar to navigate through the terminal output. Alternatively, hold downCtrland press cursor up, cursor down,Page UporPage Downto navigate using the keyboard.
使用滚动条浏览终端输出。 或者,按住Ctrl并按向上光标,向下光标,Page Up或Page Down使用键盘进行导航。
搜索 (Search)
PressCtrl+Shift+Fto open the search box:
按Ctrl+Shift+F打开搜索框:
Enter any term then use the up and down icons to search the terminal output. Click theAaicon to activate and deactivate exact-case matching.
输入任何术语,然后使用向上和向下图标搜索终端输出。 单击Aa图标可激活和停用精确大小写匹配。
复制和粘贴 (Copy and Paste)
By default, copy and paste are bound toCtrl+Shift+CandCtrl+Shift+Vrespectively, althoughCtrl+CandCtrl+Vwill also work.
默认情况下,复制和粘贴分别绑定到Ctrl+Shift+C和Ctrl+Shift+V,尽管Ctrl+C和Ctrl+V也可以。
Note: be wary thatCtrl+Ccan terminate a Linux application, so usingShiftis advisable.
注意:请警惕Ctrl+C可以终止Linux应用程序,因此建议使用Shift。
An automatic copy-on-select option is available in the global settings, and you can also paste the current clipboard item by right-clicking the mouse.
全局设置中提供了一个自动选择时复制选项,您还可以通过右键单击鼠标来粘贴当前剪贴板项目。
设定值 (Settings)
Settings are accessed from the drop-down menu orCtrl+,(comma). The configuration is defined in a singlesettings.json
file, so you may be prompted to choose a text editor. VS Code is a great choice, although Notepad is fine if you’re happy to edit without color-coding and syntax checking.
设置从下拉菜单或Ctrl+,(逗号)访问。 该配置在单个settings.json
文件中定义,因此可能会提示您选择文本编辑器。 VS Code是一个不错的选择,尽管如果您希望在不使用颜色编码和语法检查的情况下进行编辑,则记事本就可以了。
settings.json
controls:
settings.json
控件:
global settings, which apply to all profiles
全局设置 ,适用于所有配置文件
profile settings, which define profiles
配置文件设置 ,用于定义配置文件
custom color scheme settings, and
自定义配色方案设置 ,以及
keybinding settings
绑定设置
The file uses the following format:
该文件使用以下格式:
// This file was initially generated by Windows Terminal{// general settings, e.g."initialRows": 40,// profile settings"profiles":{"defaults":{// settings that apply to all profiles}"list":[// list of individual profiles, e.g.{"guid": "{81d1dceb-c123-5678-90a1-123abc456def}","name": "Windows PowerShell","commandline": "powershell.exe"},{"guid": "{91d1dceb-c123-5678-90a1-123abc456def}","name": "Ubuntu","source": "Windows.Terminal.Wsl"}]}// custom color schemes, e.g."schemes": [{"name": "My new theme","cursorColor": "#FFFFFF","selectionBackground": "#FFFFFF","background" : "#0C0C0C","foreground" : "#CCCCCC"}],// custom key bindings, e.g."keybindings:[{ "command": "find", "keys": "ctrl+shift+f" }]}
Defaults are defined indefaults.json
. Open it by holding downAltwhen clickingSettingsin the drop-down menu.
默认值在defaults.json
中定义。 单击下拉菜单中的“设置”时,按住Alt可以将其打开。
Warning:do not change the defaults file!Use it to view default settings and, where necessary, add or change a setting insettings.json
.
警告:请勿更改默认文件!使用它来查看默认设置,并在必要时在settings.json
添加或更改settings.json
。
全局设置 (Global Settings)
The following global settings are the most useful, although more are documented in the Windows Terminal documentation.
以下全局设置是最有用的,尽管Windows终端文档中记录了更多的全局设置。
"defaultProfile"
defines the GUID of the profile used as the default when Windows Terminal is launched.
"defaultProfile"
定义启动Windows Terminal时用作默认配置文件的GUID。
Set"copyOnSelect"
totrue
to automatically copy selected text to your clipboard without having to pressCtrl+Shift+C.
将"copyOnSelect"
设置为true
可以自动将选定的文本复制到剪贴板,而无需按Ctrl+Shift+C。
Set"copyFormatting"
tofalse
to just copy plain text without any styling.(I wish this were the default for every application everywhere!)
将"copyFormatting"
设置为false
即可仅复制纯文本而无需任何样式。(我希望这是所有应用程序的默认设置!)
Set"initialColumns"
and"initialRows"
to the number of characters for the horizontal and vertical dimensions.
将"initialColumns"
和"initialRows"
设置为水平和垂直尺寸的字符数。
"tabWidthMode"
can be set to:
可以将"tabWidthMode"
设置为:
"equal"
: each tab is the same width (the default)
"equal"
:每个选项卡的宽度相同(默认值)
"titleLength"
: each tab is set to the width of its title, or
"titleLength"
:每个选项卡都设置为其标题的宽度,或者
"compact"
: inactive tabs shrink to the width of their icon.
"compact"
:不活动的标签会缩小到其图标的宽度。
"disabledProfileSources"
sets an array which prevents profiles being automatically generated. For example:
"disabledProfileSources"
设置一个数组,以防止自动生成配置文件。 例如:
"disabledProfileSources": ["Windows.Terminal.Wsl","Windows.Terminal.Azure","Windows.Terminal.PowershellCore"],
This would disable all generated profiles; remove whichever ones you want to retain.
这将禁用所有生成的配置文件。 删除您要保留的任何一个。
个人资料设置 (Profile Settings)
New profiles are defined by creating an object group in the"profiles"
,"list"
array. A WSL2 Ubuntu example:
通过在"profiles"
,"list"
数组中创建一个对象组来定义新的个人档案。 一个WSL2 Ubuntu示例:
{"guid": "{91d1dceb-c123-5678-90a1-123abc456def}","name": "Ubuntu","source": "Windows.Terminal.Wsl","startingDirectory": "//wsl$/Ubuntu/home/username/","colorScheme": "Tango Dark","useAcrylic": true,"acrylicOpacity": 0.75,"hidden": false},
Each profiles is defined with the following settings:
每个配置文件均使用以下设置进行定义:
Theme-specific settings include:
特定于主题的设置包括:
Finally, add"experimental.retroTerminalEffect": true
to a profile for a retro CRT effect!…
最后,在配置文件中添加"experimental.retroTerminalEffect": true
,以实现复古的CRT效果!…
配色方案设置 (Color Scheme Settings)
Each profile’s"colorScheme"
can be set to the name of any color scheme included indefaults.json
. For example:
可以将每个配置文件的"colorScheme"
设置为defaults.json
包含的任何配色方案的名称。 例如:
"Campbell"
:
"Campbell"
:
"Campbell Powershell"
:
"Campbell Powershell"
:
"One Half Dark"
:
"One Half Dark"
:
"One Half Light"
:
"One Half Light"
:
"Tango Dark"
:
"Tango Dark"
:
"Tango Light"
:
"Tango Light"
:
"Vintage"
:
"Vintage"
:
创建自己的配色方案 (Create Your Own Color Scheme)
Your own scheme objects can be defined in the"schemes"
array insettings.json
. Each color is defined with a hex value. For example:
您可以在settings.json
的"schemes"
数组中定义自己的方案对象。 每种颜色均以十六进制值定义。 例如:
"schemes": [{"name": "My New Theme","foreground": "#EEEEEE","background": "#111111","cursorColor": "#FFFFFF","black": "#000000","red": "#CC0000","green": "#4E9A06","yellow": "#C4A000","blue": "#3465A4","purple": "#75507B","cyan": "#06989A","white": "#EEEEEE","brightBlack": "#555753","brightRed": "#EF2929","brightGreen": "#8AE234","brightYellow": "#FCE94F","brightBlue": "#729FCF","brightPurple": "#AD7FA8","brightCyan": "#34E2E2","brightWhite": "#FFFFFF"}],
The scheme can then be used by adding its"name"
to the profile’s"colorScheme"
setting. For example:
然后可以通过在配置文件的"colorScheme"
设置中添加其"name"
来使用该方案。 例如:
"colorScheme": "My New Theme"
绑定设置 (Keybinding Settings)
The"keybindings"
array insettings.json
overrides or supplements the default keybindings set indefaults.json
. Each keybinding is defined as an object with a"command"
and combination of"keys"
. For example:
settings.json
的"keybindings"
数组会覆盖或补充defaults.json
中settings.json
的默认键绑定。 每个键绑定都定义为带有"command"
和"keys"
组合的对象。 例如:
// Ctrl + Shift + F to open the search box{ "command": "find", "keys": "ctrl+shift+f" },
In some cases, the"command"
may be an application"action"
with one or more arguments. For example:
在某些情况下,"command"
可以是具有一个或多个参数的应用程序"action"
。 例如:
// Ctrl + Shift + 1 to open the first profile in a new tab{"command": { "action": "newTab", "index": 0 },"keys": "ctrl+shift+1"},
The"keys"
value accepts the modifiersctrl+,shift+, andalt+followed by:
"keys"
值接受修饰符ctrl +,shift +和alt +,后跟:
For example, if you wanted to open the search box withCtrl+F, you could add a line to the"keybindings"
array insettings.json
:
例如,如果要使用Ctrl+F打开搜索框,则可以在settings.json
的"keybindings"
数组中添加一行:
"keybindings":[{ "command": "find", "keys": "ctrl+f" }]
The search box would also open withCtrl+Shift+Fbecause that setting is defined indefaults.json
— unless you assign the key combination to another command.
搜索框也将用Ctrl+Shift+F打开,因为该设置是在defaults.json
定义的-除非您将组合键分配给另一个命令。
命令行选项 (Command Line Options)
Windows Terminal can be launched from a shortcut or any Windows or Linux terminal by runningwt.exe
. The following options are supported:
可以通过运行wt.exe
从快捷方式或任何Windows或Linux终端启动Windows终端。 支持以下选项:
You can also pass a list of commands separated by semi-colons. Commands are used to define new tabs and panes and with additional control parameters:
您还可以传递由分号分隔的命令列表。 命令用于定义新的选项卡和窗格以及其他控制参数:
例子 (Examples)
The following examples must be executed from a standardcmd
command line or a shortcut.
以下示例必须从标准cmd
命令行或快捷方式执行。
Open Windows Terminal with theUbuntu
andWindows Powershell
tabs:
使用Ubuntu
和Windows Powershell
选项卡打开Windows终端:
wt -p "Ubuntu" ; new-tab -p "Windows PowerShell"
Open Windows Terminal with theUbuntu
,Windows Powershell
, andCommand Prompt
profiles in separate panes:
在单独的窗格中使用Ubuntu
,Windows Powershell
和Command Prompt
配置文件打开Windows终端:
wt -p "Ubuntu" ; split-pane -V -p "Windows PowerShell" ; split-pane -H -p "Command Prompt"
Further examples for launching Windows Terminal from the Linux shell or Powershell are available in the Windows Terminal documentation.
Windows Terminal文档中提供了从Linux Shell或Powershell启动Windows Terminal的更多示例。
终端对待 (Terminal Treat)
I hope you enjoyed this introduction to Windows Terminal. As said, it’s the ideal accompaniment to WSL2. It’s fast, configurable, looks great, and offers all the benefits of both Windows and Linux development.
希望您喜欢Windows Terminal的介绍。 如前所述,它是WSL2的理想伴侣。 它快速,可配置,外观精美,并提供Windows和Linux开发的所有优势。
翻译自: /windows-terminal/
windows终端终端
如果觉得《windows终端终端_Windows终端机完整指南》对你有帮助,请点赞、收藏,并留下你的观点哦!