しばらくWindows10上のWSL2からLinuxが起動できない状況でしたが、
以下のWindowsUpdateでWSLが起動するようになりました(2020年10月1日現在)。
Announcing Windows 10 Insider Preview Build 20226
PS C:\> cmd /c ver
Microsoft Windows [Version 10.0.20226.1000]
今まではVisual Studio Codeを起動してから、リモートウインドウを開いていましたが、
コマンドライン(PowerShell)から起動する方法が判りましたので、メモしておきます。
PowerShellからVisual Studio Codeを起動する方は以下の通りです。
ディストリビューションはUbuntu-20.04を使用しています。
PS C:\> wsl -d {ディストリビューション名}
wsl
コマンドの他にディストリビューション名が付いた実行ファイルがあります。
例えばUbuntu 20.04 LTSの場合ubuntu2004.exeという名前になります。
PS C:\> ubuntu2004 run code
ショートカットを作成します
ワンクリックで起動できるようにショートカットを作成しておきます。
ubuntu2004.exeコマンドのフルパスを調べます
当然、which
コマンドは無いですね。
PS C:\> which ubuntu2004
which: The term 'which' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\> (gcm ubuntu2004).Definition
C:\Users\nandymak\AppData\Local\Microsoft\WindowsApps\ubuntu2004.exe
PS C:\>
ショートカットを登録します
ショートカットのリンク先に以下を登録します。
C:\Users\nandymak\AppData\Local\Microsoft\WindowsApps\ubuntu2004.exe run code