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 has fully embraced Linux, and WSL2 makes it a seamless pleasure.
Your distro’s terminal can be accessed by:
- clicking its Start menu icon
- entering
wsl
orbash
at a Powershell or command prompt - using a third-party terminal option such as Cmder, ConEmu, and Hyper with a profile which launches
%windir%\system32\bash.exe ~
- setting Linux as the default shell in VS Code by pressing Ctrl + Shift + P and typing/choosing Terminal: Select Default Shell, and selecting WSL Bash.
Windows Terminal offers a further choice, but you won’t regret installing it. The new application features:
- support for WSL2, SSH, Powershell, cmd and other command lines
- multiple tabs and split panes
- configurable themes, background images, and transparency effects
- a search box
- custom key bindings
- GPU accelerated text rendering
- a great-looking new font, Cascadia Code
- low resource usage (typically 10MB per tab)
- auto-updating (if using the Microsoft Store)
- good documentation
- and it’s open source!
How to Install Windows Terminal
The easiest way to install Windows Terminal is via the Microsoft Store:
ms-windows-store://pdp/?ProductId=9n0dx20hk701
If this link fails, try opening the Microsoft Store in your browser or launching the Microsoft Store app from the Windows Start menu and searching for “Terminal”.
Note: be careful not to select the earlier “Windows Terminal Preview” application.
Hit Get and 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.
The Windows Terminal app icon is now available in the Windows Start menu. For easier access, right-click the icon and choose Pin to Start or More, followed by Pin to taskbar.
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:
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.
Managing Tabs and Panes
Open a new tab for the default profile by clicking the + icon or Ctrl + Shift + T. To open a tab for a different profile, choose it from the drop-down menu or press Ctrl + Shift + N, where N is the profile’s number.
Press Alt + Shift + D to duplicate and split the pane. The active pane is split in two along the longest axis each time it is used:
To force creation of a:
- vertical pane, press Alt + Shift + +, or
- horizontal pane, press Alt + Shift + -
To open another profile in a new pane, hold down the Alt key when choosing it from the drop-down menu.
Hold down Alt and use the cursor keys to switch between active panes from the keyboard. The size of a pane can be adjusted by holding Alt + Shift and using the cursor keys to resize accordingly.
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, press Alt + Shift + W or enter the terminal’s standard exit command (usually exit).
Text size
The text size of the active terminal can be resized with Ctrl + + and Ctrl + -. Alternatively, hold down Ctrl and scroll the mouse wheel.
Scrolling
Use the scroll bar to navigate through the terminal output. Alternatively, hold down Ctrl and press cursor up, cursor down, Page Up or Page Down to navigate using the keyboard.
Search
Press Ctrl + Shift + F to open the search box:
Enter any term then use the up and down icons to search the terminal output. Click the Aa icon to activate and deactivate exact-case matching.
Copy and Paste
By default, copy and paste are bound to Ctrl + Shift + C and Ctrl + Shift + V respectively, although Ctrl + C and Ctrl + V will also work.
Note: be wary that Ctrl + C can terminate a Linux application, so using Shift is advisable.
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 or Ctrl + , (comma). The configuration is defined in a single settings.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.
settings.json
controls:
- 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 in defaults.json
. Open it by holding down Alt when clicking Settings in the drop-down menu.
Warning: do not change the defaults file! Use it to view default settings and, where necessary, add or change a setting in settings.json
.
Global Settings
The following global settings are the most useful, although more are documented in the Windows Terminal documentation.
"defaultProfile"
defines the GUID of the profile used as the default when Windows Terminal is launched.
Set "copyOnSelect"
to true
to automatically copy selected text to your clipboard without having to press Ctrl + Shift + C.
Set "copyFormatting"
to false
to just copy plain text without any styling. (I wish this were the default for every application everywhere!)
Set "initialColumns"
and "initialRows"
to the number of characters for the horizontal and vertical dimensions.
"tabWidthMode"
can be set to:
"equal"
: each tab is the same width (the default)"titleLength"
: each tab is set to the width of its title, or"compact"
: inactive tabs shrink to the width of their icon.
"disabledProfileSources"
sets an array which prevents profiles being automatically generated. For example:
"disabledProfileSources": [
"Windows.Terminal.Wsl",
"Windows.Terminal.Azure",
"Windows.Terminal.PowershellCore"
],
This would disable all generated profiles; remove whichever ones you want to retain.
Continue reading The Complete Guide to Windows Terminal on SitePoint.
by Craig Buckler via SitePoint
No comments:
Post a Comment