LoginSignup
2

More than 5 years have passed since last update.

Windows: VSCode を Git bash から起動

Posted at

背景と目的

自分の Windows マシンに Visual Studio Code を入れてみた。
で、自分はいままで、普段の開発は Sublime Text と Git bash を使っていて、エディタでファイルを開くときは

$ subl my-sugoi.ts

のように subl を叩いていた。普通ですね。

ところが、Windows 版 VSCode でこれと同等なコマンドは、なぜか

C:\Users\%YOU%\AppData\Local\Code\bin\code.cmd

というバッチファイルになっていて、Git bash からこれを叩くと見事にこける。
これをなんとかしたい、というのが目的。

方針

幸い、code.cmd は 中身は2行だけのうっすいラッパーなので:

$ cat /c/Users/%YOU%/AppData/Local/Code/bin/code.cmd 
@echo off
"%~dp0\..\Update.exe" --processStart Code.exe -a="%*"

やっていることを bash に翻訳してやる。
翻訳したスクリプトは、元と同じフォルダに

C:\Users\%YOU%\AppData\Local\Code\bin\code

という名前で置くことにする:

$ vi /c/Users/%YOU%/AppData/Local/Code/bin/code

中身は↓の通り:

#!/bin/bash

pushd `dirname $0` > /dev/null
SCRIPTDIR=`pwd`
popd > /dev/null
"$SCRIPTDIR/../Update.exe" --processStart Code.exe -a="$*"

これで、sublcode に置き換えて:

$ code my-sugoi.ts

で「大体同じ使い勝手」にできるので、UX() をそれほど変えずに移行できる...かもしれない。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2