きなこもち.net

.NET Framework × UiPath,Orchestrator × Azure × AWS × Angularなどの忘備録

Windows Terminal × 設定 × Tips

Purpose

この記事は、Wineods Terminalの設定とTipsをまとめることを目的としています。

Settings

Windows Terminalでは、Setting.jsonで各種設定を管理している。このJsonファイルには、Windows Terminalのメニューからアクセスできる。
Settings.jsonには、Root直下に、以下の7つのPropertiesが存在する。 - $Schem - defaultProfile - ターミナルの既定値。 - Windows Terminalを起動したときや、新しいタブを開く時に表示されるターミナルの設定。 - 初期値は、Windows PowerShellが指定されている。 - copyOnSelect - ハイライト選択したときに、選択した値をコピーするかどうかを設定する値。 - 初期値はFalse。 - copyFormatting - 値をコピーするときにふぉまっとをコピーするかを決める値。 - 初期値はFalse。 - Profiles - Windows Terminalで開くターミナルの設定をするところ。一番大事なところ。 - 初期設定では、PowerShellコマンドプロンプト、Azure用のターミナルが設定される。 - WSLのUbuntsuをWindows Storeからインストールしたら、ここの設定に自動でUbututsuが追加されていたので、頻繁に編集するものでもなさそう。 - Schemes - 配色設定のカスタマイズができる。 - 初期値は空白。 - keybindings - Windows Terminalで利用することができるショートカットキーの定義ができる。 - 初期設定で、コピペ、クイック検索、画面分割が定義されている。

基本的に、初期値の設定があれば十分だが、背景の透過性を高めたい、背景に好きな画像を表示したい、ショートカットを追加したい、新しいターミナルの設定を追加したいなどのカスタマイズをしたくなる。
そんな時は、こちらのURLにある設定を参考に追加することができる。 https://github.com/microsoft/terminal/blob/master/doc/cascadia/SettingsSchema.md

Example

今回は。以下の仕様を実現するように編集した。 - 背景をやや透明にしたい - すべてのターミナルに対して同じ変更を適用したいので、profiles - Defaults配下に設定を追加。 - ターミナルごとに色を分けたい - Profilesのそれぞれのターミナル設定に、特徴的な色を追加。 - よく使うターミナルはコマンドプロンプトにしたい - DefaultProfileに設定するGUIDをコマンドプロンプトのGUIDに変更。
- ハイライト選択で自動コピーしてほしい - copyOnSelectの値をTrueに変更。 - Ubuntuは必要。 - Windows StoreでUbuntu入れたら設定された。

// This file was initially generated by Windows Terminal 1.1.2021.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": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    // 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": true,
    // 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.
            "useAcrylic": true,
            "acrylicOpacity": 0.5
        },
        "list": [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false,
                "background": "#1100f8"
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "コマンド プロンプト",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
                "hidden": false,
                "name": "Ubuntu-20.04",
                "source": "Windows.Terminal.Wsl",
                "background": "#f87800"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": true,
                "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 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"
        }
    ]
}

Tips

Windows Terminalの設定を調べる中で見つけたいろいろなTipsをまとめてみた。

Window Terminalの起動について

Winボタン+R で”ファイル名を指定して実行”を起動後、WTと入力してEnter!

Settings.jsonへのアクセスについて

Ctrl + , (カンマ) でファイルを開ける。

画面分割について

Ctrl + "+" で、左右に分割。
Ctrl + "-" で、上下に分割。

画面分割時の挙動について

画面分割には、2つ方法がある。一つは、上記の方法。この場合は、DefaultProfileで設定されたターミナルが分割された領域に表示されることになる。今回の例では、Ubuntuターミナルを開いている時に、上記の方法で画面分割したら、コマンドプロンプトのターミナルが表示される。
一方、デフォルトで設定されているショートカットコマンドの中のSprit( Ctrl + Alt + d )を利用した場合、左右上下の指定をした分割はできないが、現在開いているターミナルと同じターミナルを開くことができる。
使い分けが面倒。

岐阜のサポート

Profilesプロパティの中に、Backgroundのイメージを指定できるプロパティ(backgroundImage)がある。このプロパティは、GIFファイルのサポート模しているため、ごちゃごちゃした動きをするGIFを背景に設定して作業をすることも可能。