#author("2023-05-10T12:48:37+09:00;2022-08-01T06:48:44+09:00","default:ryuichi","ryuichi")
#author("2023-05-10T12:50:04+09:00;2022-08-01T06:48:44+09:00","default:ryuichi","ryuichi")
* WSLからWindowsのVSCodeを起動 [#i490b987]
** 1. Windows上のcodeのパスを調べる [#q1511ce4]
PS> Get-Command code
CommandType Name Version Source
----------- ---- ------- ------
Application code.cmd 0.0.0.0 C:\software\VSCode\bin\code.cmd
- PowerShell上で上のように調べる
- ここでは '''C:\software\VSCode\bin\code.cmd'''
** 2. WSL上でパスを設定する [#ub6d9303]
*** 2.1 WindowsのパスをLinuxのパスに変換する [#t06f88c9]
$ wslpath 'C:\software\VSCode\bin\code.cmd'
/mnt/c/software/VSCode/bin/code.cmd
- WSL上でwslpathコマンドを実行して、1.で調べたパスを変換する
- ここでは '''/mnt/c/software/VSCode/bin/code.cmd'''
*** 2.2 パスをシェルのエイリアスに設定する [#ne8af02a]
$ vi ~/.bashrc
--------------------------------------------
alias code='/mnt/c/software/VSCode/bin/code'
--------------------------------------------
- .bashrcや.bash_aliasesなどのシェルの設定ファイルを開いてエイリアスを設定する
- この時、'''code.cmd''' ではなく、'''code''' とする。'''C:\software\VSCode\bin\''' の中にはWindows用のcode.cmdファイルとLinux用のcodeファイルがあり、WSLでは後者を利用する
** 3 VSCodeの起動 [#w65866bb]
** 3. VSCodeの起動 [#w65866bb]
$ cd ~/src/myproject
$ code .
- 上のように目的のフォルダに移動して、VSCodeを起動できる
** 補足 1 codeをバックグラウンドで動かしたい場合 [#tec1b1aa]
function code {
/mnt/c/software/VSCode/bin/code "$1" &
}
- 上のように.bashrcなどに記述してcode関数を作り、それを使うようにする
** 補足 2 [#f1797e06]
Do you trust the authors of the files in this folder?
Yes I trust the authors
- VScode起動時に上のように警告が出たら、Yesを選べばいい
** 補足 3 [#oaeefbdf]
ln -s /mnt/c/software/VSCode/bin/code ~/bin/code
- 上のようにシムリンクを張ってもいい