Windows ターミナルでコマンド パレットを使用する方法

コマンド パレットを使用すると、Windows ターミナル内で実行できるアクションを確認できます。 アクションの定義方法の詳細については、アクションに関するページを参照してください。

コマンド パレットの起動

コマンド パレットを起動するには、Ctrl+Shift+P キーを押します。 これは、キー バインドに commandPalette コマンドを追加することでカスタマイズできます。

{ "command": "commandPalette", "keys": "ctrl+shift+p" }

コマンド ライン モード

コマンド パレットに wt コマンドを入力する場合は、テキスト ボックス内の > 文字を削除します。 これにより、現在のウィンドウで wt コマンドが実行されます。 wt コマンドの詳細については、コマンド ラインの引数に関するページを参照してください。

Windows Terminal command line mode

コマンド ライン モードでコマンド パレットを直接呼び出すためのカスタム キー バインドを追加できます。

{ "command": "commandPalette", "launchMode": "commandLine", "keys": "" }

コマンドへのアイコンの追加

必要に応じて、settings.json で定義されている、コマンド パレットに表示されるコマンドにアイコンを追加できます。 これを行うには、icon プロパティをアクションに追加します。 アイコンには、画像へのパス、Segoe MDL2 アセットのシンボル、絵文字を含む任意の文字を指定できます。

{ "icon": "C:\\Images\\my-icon.png", "name": "New tab", "command": "newTab", "keys": "ctrl+shift+t" },
{ "icon": "\uE756", "name": "New tab", "command": "newTab", "keys": "ctrl+shift+t" },
{ "icon": "⚡", "name": "New tab", "command": "newTab", "keys": "ctrl+shift+t" }

入れ子になったコマンド

入れ子になったコマンドを使用すると、コマンド パレットの 1 つの項目の下に複数のコマンドをグループ化できます。 次の例では、フォント サイズ変更のコマンドを "Change font size..." という 1 つのコマンド パレット項目の下にグループ化しています。

{
    "name": "Change font size...",
    "commands": [
        { "command": { "action": "adjustFontSize", "delta": 1 } },
        { "command": { "action": "adjustFontSize", "delta": -1 } },
        { "command": "resetFontSize" },
    ]
}

Windows Terminal nested commands

繰り返し可能なコマンド

繰り返し可能なコマンドを使用すると、設定で定義されている他のオブジェクトから生成される、複数のコマンドを同時に作成できます。 現時点では、プロファイルと配色に関する繰り返し可能なコマンドを作成できます。 実行時に、これらのコマンドは、指定された型のオブジェクトごとに 1 つのコマンドに展開されます。

現在は、次のプロパティを反復処理できます。

iterateOn プロパティ プロパティの構文
profiles name "name": "${profile.name}"
profiles icon "icon": "${profile.icon}"
schemes name "name": "${scheme.name}"

プロファイルごとに新しいタブ コマンドを作成します。

{
    "iterateOn": "profiles",
    "icon": "${profile.icon}",
    "name": "${profile.name}",
    "command": { "action": "newTab", "profile": "${profile.name}" }
}

上の例について説明します。

  • "iterateOn": "profiles" により、プロファイルごとにコマンドが生成されます。
  • 実行時に、ターミナルは ${profile.icon} を各プロファイルのアイコンに置き換え、${profile.name} を各プロファイルの名前に置き換えます。

3 つのプロファイルがある場合:

"profiles": [
	{ "name": "Command Prompt", "icon": null },
	{ "name": "PowerShell", "icon": "C:\\path\\to\\icon.png" },
	{ "name": "Ubuntu", "icon": null },
]

上のコマンドは、次の 3 つのコマンドのように動作します。

{
    "icon": null,
    "name": "Command Prompt",
    "command": { "action": "newTab", "profile": "Command Prompt" }
},
{
    "icon": "C:\\path\\to\\icon",
    "name": "PowerShell",
    "command": { "action": "newTab", "profile": "PowerShell" }
},
{
    "icon": null,
    "name": "Ubuntu",
    "command": { "action": "newTab", "profile": "Ubuntu" }
}

入れ子になったコマンドと繰り返し可能なコマンドを組み合わせることも可能です。 たとえば、上の図に示すように、次の方法で、コマンド パレットの単一の "新しいタブ" エントリで上の 3 つの "新しいタブ" コマンドを組み合わせることができます。

{
    "name": "New tab",
    "commands": [
        {
            "iterateOn": "profiles",
            "icon": "${profile.icon}",
            "name": "${profile.name}",
            "command": { "action": "newTab", "profile": "${profile.name}" }
        }
    ]
}

Windows Terminal iterable commands

コマンドを非表示にする

キー バインドの一覧にコマンドを保持するが、コマンド パレットに表示しない場合は、その namenull に設定して非表示にできます。 次の例では、コマンド パレットで [新しいタブ] アクションが非表示になります。

{ "name": null, "command": "newTab", "keys": "ctrl+shift+t" }