Windows 11 で任意のフォルダに cd した状態で WSL の Ubuntu が WindowsTerminal で開くように以下の設定
例えばデスクトップに置いた tmp に対して WSL Ubuntu here すると
また、上記のレジストリで登録されて項目にアイコンが表示されないのも気になる点。

$icon=Get-AppxPackage|? Name -m Ubuntu|% {"$($_.InstallLocation)\$(($_|Get-AppPackageManifest).Package.Applications.Application.Executable)"} ;
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere -Name Icon -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere\command -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d `"%L`" -p Ubuntu"
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere -Name Icon -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere\command -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d `"%L`" -p Ubuntu"
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere -Name Icon -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere\command -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d . -p Ubuntu"
をしていたのだが、WSL Ubuntu here してもなぜか PowerShell が開いてしまう。例えばデスクトップに置いた tmp に対して WSL Ubuntu here すると
Microsoft Windows [Version 10.0.26200.7171] (c) Microsoft Corporation. All rights reserved. C:\Users\kou\Desktop\tmp>みたいになる。
また、上記のレジストリで登録されて項目にアイコンが表示されないのも気になる点。

WindowsTerminal の設定を確認してみると Ubuntu のエントリが二つに増えていた。


一つ目は
二つ目の有効な方のは、
WSL のイメージが、前は、
なんか、いつの間にかアイコンと同じフォルダ
更に、WSL やら Ubuntu やらが Get-AppxPackage から消えてて、どこに行ったのか不明。
Ubuntu のイメージはどこなんだろう?これか?
WSL 本体は Appx じゃなくて MSIX の方にあったが、Ubuntu は見当たらない。
wsl --list で列挙される WSL に install 済みの Distribution については以下のようにすると参照できた。
とりあえず、Windows Terminal の設定は
Profile は
にあった。


一つ目は
このプロファイルは検出されなくなりましたとなってて、どうもこれが検出できないため、PowerShell に fallback されてる模様。
この自動的に検出されたプロファイルはアンインストールされた可能性があります。行った変更は保存されますが、再インストールされるまでは使用できません。
[プロファイルの削除]
名前
ドロップダウンに表示されるプロファイルの名前です。
Ubuntu
元のソース
このプロファイルを最初に作成したソフトウェアを示します。
Windows.Terminal.Wsl
二つ目の有効な方のは、
名前みたいな感じ。
ドロップダウンに表示されるプロファイルの名前です。
Ubuntu
コマンドライン
このプロファイルで使用される実行可能ファイル
C:\WINDOWS\system32\wsl.exe --distribution-id {97705b03-93f3-4c13-88b7-eb8c228cbb3a} --cd ~
開始ディレクトリ
プロファイルが読み込まれたときに開始されるディレクトリです。
☑親プロセス ディレクトリの使用
アイコン
プロファイルで使用されるアイコンの絵文字またはイメージ ファイルの場所です。
C:\Users\kou\AppData\Local\wsl\{97705b03-93f3-4c13-88b7-eb8c228cbb3a}\shortcut.ico
...
WSL のイメージが、前は、
- %LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx
なんか、いつの間にかアイコンと同じフォルダ
- %LOCALAPPDATA%\wsl\{97705b03-93f3-4c13-88b7-eb8c228cbb3a}\ext4.vhdx
更に、WSL やら Ubuntu やらが Get-AppxPackage から消えてて、どこに行ったのか不明。
Ubuntu のイメージはどこなんだろう?これか?
- C:\Program Files\WSL\system.vhd : 388.4 MB
- C:\Program Files\WSL\tools\modules.vhd : 186.0 MB
WSL 本体は Appx じゃなくて MSIX の方にあったが、Ubuntu は見当たらない。
PS C:\Users\kou> Get-MsixPackage |? Name -m linux
Name : MicrosoftCorporationII.WindowsSubsystemForLinux
Publisher : CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
Architecture : X64
ResourceId :
Version : 2.5.7.0
PackageFullName : MicrosoftCorporationII.WindowsSubsystemForLinux_2.5.7.0_x64__8wekyb3d8bbwe
InstallLocation : C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_2.5.7.0_x64__8wekyb3d8
bbwe
IsFramework : False
PackageFamilyName : MicrosoftCorporationII.WindowsSubsystemForLinux_8wekyb3d8bbwe
PublisherId : 8wekyb3d8bbwe
IsResourcePackage : False
IsBundle : False
IsDevelopmentMode : False
NonRemovable : False
IsPartiallyStaged : False
SignatureKind : Developer
Status : Ok
wsl --list で列挙される WSL に install 済みの Distribution については以下のようにすると参照できた。
ls Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss |% {"$($_.PSChildName)`t$(gpv $_.PSPAth DistributionName)"}
結果
PS C:\Users\kou> ls Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss |% {"$($_.PSChildName)`t$(gpv $_.PSPAth DistributionName)"}
{97705b03-93f3-4c13-88b7-eb8c228cbb3a} Ubuntu
とりあえず、Windows Terminal の設定は
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions": [],
"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"keybindings":
[
{
"id": "Terminal.CopyToClipboard",
"keys": "ctrl+c"
},
{
"id": "Terminal.FindText",
"keys": "ctrl+shift+f"
},
{
"id": "Terminal.PasteFromClipboard",
"keys": "ctrl+v"
},
{
"id": "Terminal.DuplicatePaneAuto",
"keys": "alt+shift+d"
}
],
"newTabMenu":
[
{
"type": "remainingProfiles"
}
],
"profiles":
{
"defaults": {},
"list":
[
{
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"hidden": false,
"name": "Windows PowerShell"
},
{
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"hidden": false,
"name": "\u30b3\u30de\u30f3\u30c9 \u30d7\u30ed\u30f3\u30d7\u30c8"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": true,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl"
},
{
"guid": "{445d2a20-8671-52d8-800e-f67fe8d03f95}",
"hidden": false,
"name": "Ubuntu",
"source": "Microsoft.WSL"
}
]
},
"schemes": [],
"themes": []
}
%LOCALAPPDATA%\Microsoft\Windows Terminal\Fragments\Microsoft.WSL\{445d2a20-8671-52d8-800e-f67fe8d03f95}.json
PS C:\Users\kou> cat $ENV:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions": [],
"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"keybindings":
[
{
"id": "Terminal.CopyToClipboard",
"keys": "ctrl+c"
},
{
"id": "Terminal.FindText",
"keys": "ctrl+shift+f"
},
{
"id": "Terminal.PasteFromClipboard",
"keys": "ctrl+v"
},
{
"id": "Terminal.DuplicatePaneAuto",
"keys": "alt+shift+d"
}
],
"newTabMenu":
[
{
"type": "remainingProfiles"
}
],
"profiles":
{
"defaults": {},
"list":
[
{
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"hidden": false,
"name": "Windows PowerShell"
},
{
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"hidden": false,
"name": "\u30b3\u30de\u30f3\u30c9 \u30d7\u30ed\u30f3\u30d7\u30c8"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": true,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl"
},
{
"guid": "{445d2a20-8671-52d8-800e-f67fe8d03f95}",
"hidden": false,
"name": "Ubuntu",
"source": "Microsoft.WSL"
}
]
},
"schemes": [],
"themes": []
}
とりあえず、Windows Terminal の設定から無効になってる一つ目の Ubuntu を削除してみたところ、
繰り上がった二つ目の Ubuntu が呼ばれるようになって解決した。
とりあえず、WSL Ubuntu here の 1 行目を変更して以下のようにしておくのがよさそう。
繰り上がった二つ目の Ubuntu が呼ばれるようになって解決した。
とりあえず、WSL Ubuntu here の 1 行目を変更して以下のようにしておくのがよさそう。
$icon=(ls Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss |% PSPath | gp |% {@{($_.DistributionName)=(get-childitem $_.BasePath shortcut.ico)}} |% {$_["Ubuntu"].FullName})
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere -Name Icon -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Drive\Shell\WSLUbuntuHere\command -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d `"%L`" -p Ubuntu"
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere -Name Icon -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Shell\WSLUbuntuHere\command -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d `"%L`" -p Ubuntu"
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere
New-Item -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere\command
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere -Name "(Default)" -PropertyType ExpandString -Value "WSL Ubuntu here"
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere -Name Icon -PropertyType ExpandString -Value "`"$icon`""
New-ItemProperty -Force -Path Registry::HKCU\SOFTWARE\Classes\Directory\Background\Shell\WSLUbuntuHere\command -Name "(Default)" -PropertyType ExpandString -Value "`"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe`" -d . -p Ubuntu"
タグ

コメントをかく