Windows Terminal の profile の保存場所について調べると共に、設定のデフォルト値の保存場所や、Ubuntu 22.04 LTS で追加されるプロファイル {51855cb2-8cce-5362-8f54-464b92b32386} では from here が上手くできない点について調査した。
まとめると
- デフォルトパラメータは Windows Terminal のソースにハードコーディング
- Microsoft Store アプリが追加された際に AppManifest.xml に Windows Terminal 用の AppExtension 設定があるプロファイルが追加される
- {51855cb2-8cce-5362-8f54-464b92b32386} は commandline が ubuntu.exe になっており、初期ディレクトリが ~ に強制されるため from here 不能
- from here したい場合は JSON で commandline を wsl に書き換えるか、{2c4de342-38b7-51cf-b940-2309a097f518} の方のプロファイルを使う必要がある
以下がデフォルトのプロファイル
- C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.16.10261.0_x64__8wekyb3d8bbwe\default.json
以下がユーザー毎の差分
- %LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
GUID で profile を参照しているのだが、
Windows Terminal を使うアプリ、例えば WSL の Ubuntu だと以下に Windows Terminal に取り込まれると思われる設定 "updates": "{2c4de342-38b7-51cf-b940-2309a097f518}" がある。
- C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_2004.2022.1.0_x64__79rhkp1fndgsc\Terminal\Fragments\terminal.json
- C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu_2204.2.33.0_x64__79rhkp1fndgsc\Terminal\Fragments\terminal.json
"profiles": [ { "updates": "{2c4de342-38b7-51cf-b940-2309a097f518}", // We have to hide this autogenerated profile as we can't change the name of existing profiles. // This would use WSLID like "Ubuntu20.04LTS" which is hard to read. "hidden": true }, { "name": "Ubuntu", "colorScheme": "UbuntuColorScheme", "commandline": "ubuntu.exe", "tabTitle": "Ubuntu", // This would be the idea once https://github.com/microsoft/terminal/issues/10359 is fixed. // "icon": "ms-appx:///Assets/Square44x44Logo.targetsize-32.png", "icon": "https://assets.ubuntu.com/v1/49a1a858-favicon-32x32.png", "cursorShape": "filledBox", "font": { // Not possible right now as we have multiple appx which could ship it and needs a store // permission: https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#share-fonts-with-other-windows-applications // Also, referencing it if it does not exist will show an error message when opening // the profile. //"face": "Ubuntu Mono", "face": "Cascadia Mono", "size": 13 } } ],
"profiles": [ { "updates": "{2c4de342-38b7-51cf-b940-2309a097f518}", // We have to hide this autogenerated profile as we can't change the name of existing profiles. // This would use WSLID like "Ubuntu-20.04" which is hard to read. "hidden": true }, { "name": "Ubuntu", "colorScheme": "Ubuntu-ColorScheme", "commandline": "ubuntu.exe", "tabTitle": "Ubuntu", // This would be the idea once https://github.com/microsoft/terminal/issues/10359 is fixed. // "icon": "ms-appx:///Assets/Square44x44Logo.targetsize-32.png", "icon": "https://assets.ubuntu.com/v1/49a1a858-favicon-32x32.png", "cursorShape": "filledBox", "font": { // Not possible right now as we have multiple appx which could ship it and needs a store // permission: https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#share-fonts-with-other-windows-applications // Also, referencing it if it does not exist will show an error message when opening // the profile. //"face": "Ubuntu Mono", "face": "Cascadia Mono", "size": 13 } } ],
Windows Terminal がこれをどうやって読み込んでいるか、または Windows Terminal にこれをどうやって読み込ませているかは不明な上、GUI の設定画面では JSON にないパラメータが幾つかみられたので調べてみた。
以下の記事によると、{2c4de342-38b7-51cf-b940-2309a097f518} のプロファイルは「ダイナミックプロファイル」とか呼ばれているものの一つらしくて、「Windows Terminalは初期化時(通常はインストール時)にインストールされているシェルを調べて、自動登録する」んだそうな。
- +Digital Powered by mynavi / 2022-04-07: Windows Terminal ベスト設定 第3回「プロファイル 基本編」 # ダイナミックプロファイル
Microsoft Store 版の WSL に wsl --update した環境ではこれに加えて、"guid": "{51855cb2-8cce-5362-8f54-464b92b32386}" が重複したプロファイル名 "name": "Ubuntu" で
- %LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
具体的には以下のような感じ。
{ "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "startingDirectory": null }, { "guid": "{51855cb2-8cce-5362-8f54-464b92b32386}", "hidden": false, "name": "Ubuntu", "source": "CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc", "startingDirectory": null }
"{2c4de342-38b7-51cf-b940-2309a097f518}" の方が元々あったプロファイルで、
"{51855cb2-8cce-5362-8f54-464b92b32386}" が後から追加されたものだと思うのだが、
環境によっては、json 内での出現順序が逆になっている場合があるって、
その環境だとなぜか 20200531: Windows Terminal でやってる from here の設定が上手く働かない。
Windows Terminal の設定画面(GUI)での表示は以下。
![]() | ![]() |
{2c4de342-38b7-51cf-b940-2309a097f518} | {51855cb2-8cce-5362-8f54-464b92b32386} |
source やその他 commandline 等の記述から考えると、
- C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_2004.2022.1.0_x64__79rhkp1fndgsc\Terminal\Fragments\terminal.json
- C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu_2204.2.33.0_x64__79rhkp1fndgsc\Terminal\Fragments\terminal.json
{2c4de342-38b7-51cf-b940-2309a097f518} の commandline や icon は json が見当たらないのだけど builtin なのでソース参照なのだろうか?という疑問も生じたのでソース漁ってみると、以下の部分で generate してそうな雰囲気。
- GitHub / microsoft / terminal / blob / 1bec08ec0a2c88be2a4662c38bb511ef325413a3 / src / cascadia / TerminalSettingsModel / WslDistroGenerator.cpp # L56
- GitHub / microsoft / terminal / blob / 1bec08ec0a2c88be2a4662c38bb511ef325413a3 / src / cascadia / LocalTests_SettingsModel / DeserializationTests.cpp # L609-L622
terminal.json を拾う仕組みは以下に説明があった。
- GitHub / microsoft / terminal / blob / 1bec08ec0a2c88be2a4662c38bb511ef325413a3 / doc / specs / Proto 0extensions-spec.md # L261-L302
という事でどうも、Microsoft Store アプリの AppxManifest.xml に所定の様式で記述しておくと、拾われる模様。
- C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu_2204.2.33.0_x64__79rhkp1fndgsc\AppxManifest.xml
<uap3:Extension Category="windows.appExtension"> <uap3:AppExtension Name="com.microsoft.windows.terminal.settings" Id="Ubuntu" DisplayName="Ubuntu" PublicFolder="Terminal" /> </uap3:Extension>という記述があるので、これが拾われているようだ。
一方、
- C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_2004.2022.1.0_x64__79rhkp1fndgsc\AppxManifest.xml
このため、CanonicalGroupLimited.UbuntuonWindows_2004.2022.1.0_x64__79rhkp1fndgsc はプロファイルを更新せず、
CanonicalGroupLimited.Ubuntu_2204.2.33.0_x64__79rhkp1fndgsc のみがプロファイルを更新したものと思われる。
で、{51855cb2-8cce-5362-8f54-464b92b32386} については from here する際にちょっと問題がある。
commandline が ubuntu.exe になっているので、起動した際の current directory が強制的に ~ になってしまう。
このため 20200531: Windows Terminal で from here のためにやってる
wt -d . -p Ubuntuのような方法でプロファイル名で起動した際、同名の {51855cb2-8cce-5362-8f54-464b92b32386} に食われてしまうと強制的に ~ に移動してしまうため from here が上手く機能しない。
これは、settins.json で {2c4de342-38b7-51cf-b940-2309a097f518} を {51855cb2-8cce-5362-8f54-464b92b32386} より前に配置することで優先的に Windows Terminal に {2c4de342-38b7-51cf-b940-2309a097f518} を拾わせてやるか
wt -d . -p {2c4de342-38b7-51cf-b940-2309a097f518}のように guid で profile を指定することで回避は出来るのだが、ubuntu.exe、なんで初期ディレクトリが ~ に固定なん?
タグ
コメントをかく