文書の過去の版を表示しています。
Windows Terminal
Windows Terminal は Windows 10 向けの新しいコマンドプロンプトを提供する。Linux ターミナルのようにマルチタブなどの機能も提供されている。
2020/05/14 現在のバージョンは Windows Terminal Version: 0.11.1333.0 (1.0RC2) である。
Microsoft Store からインストールできる。
サイト: Windows Terminal Preview v0.3 Release | Windows Command Line Tools For Developers
ソースコード: GitHub - microsoft/terminal: The new Windows Terminal, and the original Windows console host -- all in the same place!
システム必要条件
Windows Terminal requires Windows 10 1903 (build 18362) 以降
Windows Version Build 情報
$ cmd /c ver
Microsoft Windows [Version 10.0.18363.836]
インストール
Scoop によるインストール
$ scoop bucket add dorado https://github.com/h404bi/dorado
Checking repo... ok The dorado bucket was added successfully.
$ sudo scoop install windowsterminal-np --global
Installing 'windowsterminal-np' (0.11.1333.0) [64bit] Microsoft.WindowsTerminal_0.11.1333.0_8wekyb3d8bbwe.msixbundle (18.2 MB) [====================================] 100% Checking hash of Microsoft.WindowsTerminal_0.11.1333.0_8wekyb3d8bbwe.msixbundle ... ok. Running installer script... Linking C:\ProgramData\scoop\apps\windowsterminal-np\current => C:\ProgramData\scoop\apps\windowsterminal-np\0.11.1333.0 'windowsterminal-np' (0.11.1333.0) was installed successfully!
Microsoft Store よりインストールする場合
Microsoft Store - Windows Terminal
コピー & ペースト
CTRL + C : Cancel CTRL + Shift + C : Copy CTRL + Shift + V : Paste
Copy & Paste Keybindings · Issue #968 · microsoft/terminal · GitHub
設定
settings.json のセクション構成
セクション | 補足 |
---|---|
グローバル設定 (Global Settings - start) | {
|
+- プロファイル (Profiles) | "profiles": { ... }, |
+- 配色 (Color Schemes) | "schemes": [], |
+- キーバインド (Key Bindings) | "keybindings": [ ... ] |
グローバル設定 (Global Settings - end) | }
|
settings.json の設定例
- settings.json
// This file was initially generated by Windows Terminal 0.11.1251.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": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "initialCols": 120, "initialRows": 35, // 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": false, // 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 "fontFace": "HackGen35 Console", "fontSize" : 9, "backgroundImage": "C:\\Users\\tomoyan\\Pictures\\mg_chara.png", "backgroundImageStretchMode": "none", "backgroundImageAlignment": "bottomRight", "backgroundImageOpacity": 0.5 //"colorScheme": "Campbell" //"colorScheme": "Campbell Powershell" //"colorScheme": "Vintage" //"colorScheme": "One Half Dark" //"colorScheme": "One Half Light" //"colorScheme": "Solarized Dark" //"colorScheme": "Solarized Light" }, "list": [ { "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "hidden": false, "name": "PowerShell Core", //"source": "Windows.Terminal.PowershellCore", "commandline": "%USERPROFILE%\\scoop\\apps\\powershell\\current\\pwsh.exe", "icon": "%USERPROFILE%\\scoop\\apps\\powershell\\current\\assets\\Powershell_av_colors.ico", "colorScheme": "Campbell", "startingDirectory" : "%USERPROFILE%" }, { // Make changes here to the powershell.exe profile "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", "hidden": false, "name": "Windows PowerShell", "commandline": "powershell.exe", "startingDirectory" : "%USERPROFILE%" }, { // Make changes here to the cmd.exe profile "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", "hidden": false, "name": "コマンドプロンプト", "commandline": "cmd.exe", "colorScheme": "One Half Dark", "startingDirectory" : "%USERPROFILE%" }, { "guid": "{d3f31bee-5823-5ed8-8e04-f31ed54f2cd9}", "hidden": false, "name": "FedoraRemix", "source": "Windows.Terminal.Wsl" }, { "guid": "{aa8efdb5-3cbe-50b2-a332-9203dc1ee217}", "hidden": false, "name": "Fedora", "source": "Windows.Terminal.Wsl" }, { "guid": "{8f5a3735-826f-59b7-9b09-6584f5cdcfc6}", "hidden": false, "name": "Fedora-WSL1", "source": "Windows.Terminal.Wsl" }, { "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}", "hidden": false, "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" } ] }
※backgroundImage は 400 x 300px の png 画像を使用。
WSL の GUID を調べる方法
Get-ChildItem コマンドレットでレジストリを調べる。
$ Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss
Name フィールドが WSL の GUID である。
Hive: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss Name Property ---- -------- {874A2A70-6EAF-42C1-A6F6-1C2EA DistributionName : FedoraRemix C2BFA52} BasePath : C:\wsl\FedoraRemix State : 1 Version : 2 DefaultEnvironment : {HOSTTYPE=x86_64, LANG=en_US.UTF-8, PATH=/usr/local/sbin:/usr/loc al/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games, TERM=xterm-256color} DefaultUid : 1000 KernelCommandLine : BOOT_IMAGE=/kernel init=/init ro Flags : 15 {CC54D096-DBCD-4D93-93A5-899AE DistributionName : Fedora-WSL1 35559B4} BasePath : C:\wsl\Fedora-WSL1 State : 1 Version : 2 DefaultEnvironment : {HOSTTYPE=x86_64, LANG=en_US.UTF-8, PATH=/usr/local/sbin:/usr/loc al/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games, TERM=xterm-256color} DefaultUid : 0 KernelCommandLine : BOOT_IMAGE=/kernel init=/init ro Flags : 7 {E74B61AB-F675-4518-A0E3-BCEE9 DistributionName : Fedora C7F8E9C} BasePath : C:\wsl\Fedora State : 1 Version : 2 DefaultEnvironment : {HOSTTYPE=x86_64, LANG=en_US.UTF-8, PATH=/usr/local/sbin:/usr/loc al/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games, TERM=xterm-256color} DefaultUid : 1000 KernelCommandLine : BOOT_IMAGE=/kernel init=/init ro Flags : 15 {F9260EF7-5866-4DAC-8E4F-86487 DistributionName : Fedora32 1004DA4} BasePath : C:\wsl\Fedora32 State : 1 Version : 2 DefaultEnvironment : {HOSTTYPE=x86_64, LANG=en_US.UTF-8, PATH=/usr/local/sbin:/usr/loc al/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games, TERM=xterm-256color} DefaultUid : 0 KernelCommandLine : BOOT_IMAGE=/kernel init=/init ro Flags : 15
MSYS2 MinGW 64-bit を追加する
GUID を生成する。
> powershell -Command "[Guid]::NewGuid()" Guid ---- a9c3b42d-34ef-4488-aba4-98fca245f6b9
生成した GUID を使用して profiles を以下の様にすると MSYS2 MinGW 64-bit が上手くタブになる。
- profile.json
{ "profiles" : [ ... { "acrylicOpacity" : 0.75, "closeOnExit" : true, "colorScheme" : "Campbell", "commandline" : "cmd.exe /c \"set CHERE_INVOKING=1&& set MSYSTEM=MINGW64&& C:\\msys64\\usr\\bin\\bash.exe --login\"", "cursorColor" : "#FFFFFF", "cursorShape" : "bar", "fontFace" : "Consolas", "fontSize" : 10, "guid" : "{a9c3b42d-34ef-4488-aba4-98fca245f6b9}", "historySize" : 9001, "icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png", "name" : "MSYS2 MinGW 64-bit", "padding" : "0, 0, 0, 0", "snapOnInput" : true, "startingDirectory" : "c:\\msys64\\home\\%USERNAME%", "useAcrylic" : true },
参考文献
失敗例
生成した GUID を使用して profiles を以下の様に追加してみたが、MSYS2 MinGW 64-bit は起動できるもののタブにはならなかった。(別窓になってしまう)
- profile.json
{ "profiles" : [ ... { "acrylicOpacity" : 0.75, "closeOnExit" : true, "colorScheme" : "Campbell", "commandline" : "C:\\msys64\\msys2_shell.cmd -mingw64", "cursorColor" : "#FFFFFF", "cursorShape" : "bar", "fontFace" : "Consolas", "fontSize" : 10, "guid" : "{a9c3b42d-34ef-4488-aba4-98fca245f6b9}", "historySize" : 9001, "icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png", "name" : "MSYS2 MinGW 64-bit", "padding" : "0, 0, 0, 0", "snapOnInput" : true, "startingDirectory" : "%USERPROFILE%", "useAcrylic" : true },
デフォルトで起動するターミナルを PowerShell から コマンドプロンプト(cmd) に変更する場合
defaultProfile に profiles の guid を設定すると変更できる。
"profiles" : [ { ... "commandline" : "powershell.exe", "guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", "name" : "Windows PowerShell", ... }, { ... "commandline" : "cmd.exe", "guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", "name" : "cmd", ... }, ],
defaultProfile を {61c54bbd-c2c6-5271-96e7-009a87ff44bf}(Windows PowerShell) から {0caa0dad-35be-5f56-a8ff-afceeeaa6101}(cmd) に変更する。
- profile.json
{ "globals" : { "alwaysShowTabs" : true, "defaultProfile" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", "initialCols" : 120, "initialRows" : 30, "keybindings" : [ { "command" : "closePane", "keys" : [ "ctrl+shift+w" ] },
トラブルシューティング
長時間実行プロセスを Ctrl + C で終了すると PowerShell が終了する
PowerShell 7.0.2 Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/powershell Type 'help' to get help. PS C:\Users\nakayama> cd d:\wsl PS D:\wsl> xz .\fedora.tar [プロセスはコード 3221225786 で終了しました]
英語では以下のようにシェルが終了する。
[process exited with code 3221225786]
設定 (settings.json) の “source” コメントアウトして、以下のように “commandline” にフルパス記述するように修正する。
- settings.json
"list": [ { "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "hidden": false, "name": "PowerShell Core", //"source": "Windows.Terminal.PowershellCore", "commandline": "%USERPROFILE%\\scoop\\apps\\powershell\\current\\pwsh.exe", "icon": "%USERPROFILE%\\scoop\\apps\\powershell\\current\\assets\\Powershell_av_colors.ico", "colorScheme": "Campbell", "startingDirectory" : "%USERPROFILE%" } ]
バージョンアップ後にユーザー設定読み込みエラーが発生する
バージョンアップ後に以下のエラーが発生する。
ユーザー設定の読み込み中にエラーが発生しました The "globals" property is deprecated - your settings might need updating. For more info, see this web page.
For more info, see this web page.
"globals" プロパティは廃止されました - 設定の更新が必要になる場合があります。詳細については、この Web ページを参照してください。
以下のような “globals” プロパティの場合
- profile.json
{ "$schema": "https://aka.ms/terminal-profiles-schema", "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "globals": { "initialCols" : 120, "initialRows" : 35 }, "profiles": { ... } }
“globals” プロパティを削除して内容を “defaultProfile” と同一レベルに記述する。
- profile.json
{ "$schema": "https://aka.ms/terminal-profiles-schema", "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "initialCols" : 120, "initialRows" : 35, "profiles": { ... } }
参考文献
Windows Terminal User Documentation
Editing Windows Terminal JSON Settings
Windows Terminal (Preview) メモ - Qiita
【文字幅 半角3:全角5 も追加】Ricty を神フォントだと崇める僕が、フリーライセンスのプログラミングフォント「白源」を作った話 - Qiita
Windows Terminal Tips - Qiita
Windows ターミナルの配色 | Microsoft Docs
PowerShellコンソールの表示色についてのちょっとした話 - しばたテックブログ
Write-Host
How to use ANSI escape sequence color codes for PSReadLineOption v2 in Powershell console? - Stack Overflow
DHowett-MSFT ( Dustin L. Howett (MSFT) )
command line - Print a 256-color test pattern in the terminal - Ask Ubuntu