All about Windows Terminal – LLODO


Soon Windows 11 will remove CMD and replace it with Windows Terminal, to catch up with the trend, in this article, we will learn Windows Terminal, the ideal support software for WSL2. It’s fast, configurable, beautiful, and offers all the benefits of developing both Windows and Linux.

Windows has fully embraced Linux and WSL2 makes the Linux experience more seamless.

The distribution’s terminal can be accessed with:

1. Click Start menu
2. Type wsl or bash at Powershell or command prompt
3. Use third-party terminal options like Cmder, ConEmu and Hyper with launch configuration %windir%system32bash.exe ~
4. Set Linux as default shell in VS Code by pressing Ctrl + Shift + P and typing Terminal: Select Default Shell and choose WSL Bash.

Windows Terminal (downloadable from the Microsoft Store) offers more options. New app features:

  • Support for WSL2, SSH, Powershell, cmd and other command lines
  • Many tabs and small compartments
  • Configurable themes, backgrounds and transparency effects
  • Search box
  • Customize keyboard shortcuts
  • GPU-accelerated rendering
  • New better font, Cascadia Code
  • Uses less resources (usually 10MB per tab)
  • Auto-update (if using Microsoft Store)
  • Detailed Documentation
  • Open source

All about Windows Terminal

How to install Windows Terminal

The easiest way to install Windows Terminal is through the Microsoft Store:

ms-windows-store://pdp/?ProductId=9n0dx20hk701

If this link fails, try opening the Microsoft Store in your browser or launch the Microsoft Store app from the Windows Start Menu and search for “Terminal”.

Note: do not select the “Windows Terminal Preview” application.

All about Windows Terminal 19

Click Get and wait a few seconds for the installation to complete.

If you don’t have access to the Store, you can get the latest release from GitHub here.

The Windows Terminal application icon is now available in the Windows Start Menu. For easier access, right-click on the icon and select Pin to Start or Morethen select Pin to taskbar.

Getting Started with Windows Terminal

When first run, Windows Terminal uses Powershell as the default configuration. You can use the drop-down menu available to launch other tabs and access settings:

All about Windows Terminal 20

Terminal automatically creates configurations for all WSL distributions and Windows shells you have installed, although creation can be turned off in global settings.

Manage tabs and panes

Open a new tab for the default profile by clicking the . icon + or Ctrl + Shift + UP. To open a tab for another profile, select it from the drop-down menu or press Ctrl + Shift + N, where N is the configuration number.

Press Alt + Shift + EASY for copying and dividing panes. The Activity Pane is split into two vertical rows each time it is used:

All about Windows Terminal 21

To force generate:

  • vertical pane, press Alt + Shift + “+” or
  • horizontal pane, press Alt + Shift + “-”

To open another profile in a new pane, hold down the Alt key while selecting it from the drop-down menu.

Press and hold the Alt key and use the cursor keys to switch between panes from the keyboard. The size of the pane can be adjusted by holding Alt + Shift and using the cursor keys to resize accordingly.

Tabs can be renamed by double clicking on the text. You can also change the name or color by right-clicking the tab and selecting the menu:

All about Windows Terminal 22

This affects only the current tab; it does not permanently change the profile.

To close the active pane or tab, press Alt + Shift + W or enter the command exit.

Font size

The text size of the active terminal can be changed with Ctrl + “+” and Ctrl + “-”. Alternatively, you can also hold Ctrl and scroll the mouse wheel.

Roll

Use the scroll bar to navigate the terminal output. Alternatively, hold 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:

All about Windows Terminal 23

Type any text, then use the up and down icons to search for output in the terminal. Click the Aa icon to activate and deactivate case matching.

Copy and paste

By default, copy and paste is associated with Ctrl + Shift + CLOSE and Ctrl + Shift + DRAWin spite of Ctrl + and Ctrl + DRAW will also work.

Note: Ctrl + C can end a Linux application, so you should use Shift.

Auto copy on selection option is available in general settings and you can also paste clipboard by right clicking.

Settings

Settings are accessed from the drop-down menu or Ctrl + “,” (comma). The configuration is defined in a 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:

  1. global settings, apply to all configurations
  2. profile settings, define profiles
  3. custom color scheme settings and
  4. 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" }
  ]

}

The default value is defined in defaults.json. Open it by holding Alt key when clicking Settings in the drop-down menu.

Warning: do not change the default file. Use it to view default settings and, if necessary, add or change settings in settings.json.

Global Settings

“defaultProfile” defines the GUID of the profile to be 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 copy just plain text without any formatting.

Set “InitialColumns” and “initialRows” to the number of characters for horizontal and vertical dimensions.

“tabWidthMode” can be set to:

  1. “equal”: each tab has the same width (default)
  2. “titleLength”: each tab is set to the width of the title or
  3. “compact”: inactive tabs shrink to the width of the icon.

“DisableProfileSources” sets an array that prevents auto-generated profiles. For example:

"disabledProfileSources": [
  "Windows.Terminal.Wsl",
  "Windows.Terminal.Azure",
  "Windows.Terminal.PowershellCore"
],

This will disable all created profiles; get rid of any that you want to keep.

Profile Settings

The new profile is defined by creating a group of objects in the array “profiles”, “list”. An Ubuntu WSL2 example:

{
  "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 profile is defined with the following settings:

Setting Describe
"guid" a unique identifier (required). For new configurations, you can generate a GUID online at Guidgen.com
"source" profile builder. This is only used when the profile has been automatically added and not edited.
"commandline" executable to run assuming no “source” is set. For example, this could be an SSH command such as “ssh yourname@domain.com”
"startingDirectory" directory where the shell starts. For WSL distributions it is best to be set to “//wsl$/Ubuntu/home/username/” where username is the user created during the installation
"name" profile name is displayed in the drop-down menu
"tabTitle" name displayed in tab title
"suppressApplicationTitle" set true to force “tabTitle” or “name” in bash
"icon" The full path to the icon is shown in the drop-down menus and tabs, e.g. “C: /images/tux.png”. 24-bit PNG is the best choice; SVG is not supported
"hidden" if set to true, the profile will not be displayed in the dropdown
"fontFace" use a specific font
"fontSize" use a specific font size integer
"fontWeight" use specific font weights. This can be an OpenType integer or a keyword:: "normal", "thin", "extra-light", "light", "semi-light", "medium", "semi-bold", "bold", "extra-bold", "black", "extra-black"
"padding" padding around the text at the edge of the window. One, two or four comma-separated values ​​can be set, e.g. “1, 2, 3, 4” to set left, top, right and bottom respectively
"antialiasingMode" anti-aliasing method. Set to “grayscale” (default), “cleartype” or “aliased”
"cursorShape" pointer type. Set to “bar” (default), “vintage”, “underscore”, “fillBox” or “blankBox”
"cursorHeight" the height of the “vintage” pointer is defined as an integer between 25 and 100
"cursorColor" cursor color, defined as “#rgb” or “#rrggbb”

Theme-specific settings include:

settings description
"colorScheme" the name of a color scheme as defined in defaults.json or the “schemes” list in settings.json
"useAcrylic" set true to use frosted glass background effect
"acrylicOpacity" acrylic opacity from 0 (fully transparent) to 1 (fully opaque)
"backgroundImage" the full path to the background image, e.g. “C: /images/background.png”
"backgroundImageOpacity" background opacity from 0 (fully transparent) to 1 (fully opaque)

Finally, add “Experiment.retroTerminalEffect”: true to the configuration for the classic CRT effect.

All about Windows Terminal 24

Color Scheme Settings

The “ColorScheme” of each profile can be set to the name of any color scheme included in defaults.json. For example:

"Campbell":

All about Windows Terminal 25

"Campbell Powershell":

All about Windows Terminal 26

"One Half Dark":

All about Windows Terminal 27

"One Half Light":

All about Windows Terminal 28

"Tango Dark":

All about Windows Terminal 29

"Tango Light":

All about Windows Terminal 30

"Vintage":

All about Windows Terminal 31

Create your own color palette

Each color is identified with a hex value. For example:

"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 “colorScheme” setting of the profile. For example:

"colorScheme": "My New Theme"

Keybinding Settings

The “keybindings” array in settings.json overrides or supplements the default keybindings set in defaults.json. Each keybinding is defined as an object with a “command” and a combination of “keys”. For example:

// Ctrl + Shift + F để mở hộp tìm kiếm
{ "command": "find", "keys": "ctrl+shift+f" },

In some cases, the “command” can be an application “action” with one or more arguments. For example:

// Ctrl + Shift + 1 để mở hồ sơ đầu tiên trong tab mới
{
  "command": { "action": "newTab", "index": 0 },
  "keys": "ctrl+shift+1"
},

The value “keys” accepts the ctrl +, shift +, and alt + modifiers, followed by:

type keys
function keys f1-f24
alphanumeric keys a-z, 0-9
Icon -, =, [], , ;, ', ,, ., /
cursor key down, left, right, up, pagedown, pageup, pgdn, pgup, end, home, plus

action key

tab, enter, esc, escape, space, backspace, delete, insert
number keys numpad_0-numpad_9, numpad0-numpad9, numpad_add, numpad_plus, numpad_decimal, numpad_period, numpad_divide, numpad_minus, numpad_subtract, numpad_multiply

For example, if you wanted to open the search box with Ctrl + F, you could add a line to the “keybindings” array in settings.json:

"keybindings":
[
  { "command": "find", "keys": "ctrl+f" }
]

The search box will also open with Ctrl + Shift + F because that setting is defined in defaults.json – unless you assign that key combination to another command.

Command line options

Windows Terminal can be launched from a shortcut or any Windows or Linux terminal by running wt.exe. The following options are supported:

option description
--help, -h, -?, /? show help
--maximized, -M maximum launch
--fullscreen, -F launch full screen

You can also pass a semicolon-separated list of commands. Commands used to define new tabs and panes and with additional control parameters:

command parameters description
new-tab --profile or -p, --startingDirectory or -d, commandline, --title open a new tab
split-pane --horizontal or -H, --vertical or -V, --profile or -p, --startingDirectory or -d, commandline, --title open a new compartment
focus-tab --target or -t focus a tab

Examples

The following examples must be executed from the standard cmd command line or a shortcut.

Open Windows Terminal with Ubuntu and Windows Powershell tabs:

wt -p "Ubuntu" ; new-tab -p "Windows PowerShell"

Open Windows Terminal with Ubuntu, Windows Powershell and Command Prompt configuration in separate panes:

wt -p "Ubuntu" ; split-pane -V -p "Windows PowerShell" ; split-pane -H -p "Command Prompt"

All about Windows Terminal 32

More examples to launch Windows Terminal from Linux shell or Powershell are available in Windows Terminal documentation.



Link Hoc va de thi 2021

Chuyển đến thanh công cụ