フォルダの Shift-右クリックで WSL2 の Ubuntu を起動する「Ubuntu Here」
Windows のフォルダーを指定して Shift-右クリックで WSL2 の Ubuntsu のシェルを起動する Ubuntu Here を作りました。この右クリックメニューは Microsoft PowerToys に付属の Open Command Window Here を修正して作成しています。
Ubuntuhere.inf のコード
以下のテキストで Ubuntuhere.inf を作成します。
作成したファイルを右クリックしてインストールします。
この inf ファイルはアンインストールに対応しています。
[Version]
Signature=$CHICAGO$
[DefaultInstall]
AddReg=Reg.Settings
AddReg=Reg.Uninstall
CopyFiles=Inf.Copy
[DefaultUninstall]
DelReg=Reg.Settings
DelReg=Reg.Uninstall
DelFiles=Inf.Copy
[Reg.Settings]
HKCR,Directory\Shell\Ubuntuhere
HKCR,Directory\Shell\Ubuntuhere,,,"%MENUITEM%"
HKCR,Directory\Shell\Ubuntuhere\command,,,"%11%\cmd.exe /c ""cd """"%1"""" && wsl -d Ubuntu-24.04"""
HKCR,Drive\Shell\Ubuntuhere
HKCR,Drive\Shell\Ubuntuhere,,,"%MENUITEM%"
HKCR,Drive\Shell\Ubuntuhere\command,,,"%11%\cmd.exe /c ""cd """"%1"""" && wsl -d Ubuntu-24.04"""
[Reg.Uninstall]
HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%
HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%,DisplayName,,"%NAME%"
HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%,UninstallString,,"Rundll32.exe setupapi.dll,InstallHinfSection DefaultUninstall 132 %17%\Ubuntuhere.inf"
[Inf.Copy]
Ubuntuhere.inf
[DestinationDirs]
Inf.Copy=17
[SourceDisksNames]
55=%DISKNAME%
[SourceDisksFiles]
Ubuntuhere.inf=55
[Strings]
NAME = "Ubuntu Here"
MENUITEM = "Ubuntu Here"
DISKNAME = "Setup Files"
フォルダーの Shit-右クリックで起動
フォルダーの Shift-右クリックのメニューで Ubuntu Here を選択すると WSL2 の Ubuntu の Shell が起動します。
カスタマイズ方法
独自のコマンドを右クリックで実行するためのカスタマイズ方法の解説です。この修正方法を使うと powershell を起動する右クリックメニューなども作成可能です。
1. 右クリックの名前変更
Ubuntu Here
を検索して置換します。例えばUbuntu 20.04
に置換します。
2. inf ファイル名の変更
Ubuntuhere.inf
を検索して置換します。例えばUbuntu20_04.inf
に置換します。ファイル名もUbuntu20_04.inf
に変更します
3. 右クリックで実行するコマンドの変更
"%11%\cmd.exe /c ""cd """"%1"""" && wsl -d Ubuntu-24.04"""
を検索して置換します。例えば"%11%\cmd.exe /c ""cd """"%1"""" && wsl -d Ubuntu-20.04"""
に置換します。
コマンドの記述方法について、%1
は右クリックしたフォルダ名です。"
ダブルクオートをコマンドに含める場合は、""
二つのダブルクオートを使用します。上のコマンドはcmd.exe /c "cd ""%1"" && wsl -d Ubuntu-20.04"
が元のコマンドです。