LoginSignup
4
3

More than 3 years have passed since last update.

code-insidersコマンドをCUIから設定する方法

Last updated at Posted at 2020-03-15

code-insidersコマンドをCUIから設定する方法

Macの環境移行をスクリプトで行いたかったのでcode-insidersコマンドを使えるようにターミナルから設定したかったが、ドキュメントの方法ではうまくいかなかったのでメモ

結果的に、パスに新たに追記することなくコマンドを有効にできたので、副次的な利点も得られる。
codeコマンドに応用することも可能

結論

解決方法

vscodeとvscode insidersのコマンド

VisualStudio CodeVisualStudio Code Insidersはシェルから操作することができる。コマンドはそれぞれcodecode-insidersである。

GUIから設定する方法

codeコマンドもcode-insidersコマンドもGUIのコマンドパレットからは正常に設定できる。
方法は公式ドキュメント1参照

CUIから設定する方法

普通のvscodeの場合 (公式)

CUIから設定するには、ドキュメント1の通り以下のコマンドを実行する。

echo 'export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"' >> ~/.bash_profile
source ~/.bash_profile

vscode insidersの場合 (失敗)

vscode insidersのcode-insidersコマンドをCUIから使えるようにする方法はドキュメントに載っていない(たぶん)。
codeコマンドと同じ方法でやってみる。

echo 'export PATH="$PATH:/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin"' >> ~/.bash_profile
source ~/.bash_profile

しかし、以下のように確認してみると使えないことがわかる。

code-insiders --version

bash: code-insiders: Command not found

shellを再読み込みしても変わらず...

考察

どうやら、GUIで設定した場合の内部的な処理はCUIと異なる。
CUIで設定した場合、コマンドの実行ファイルが存在しているディレクトリを直接PATHに追加している。
一方、GUIで設定した場合は/usr/local/binに実行ファイルへのシンボリックリンクを貼っている。/usr/local/binはデフォルトで$PATHに記述されているので、パスの追加を行う必要はない。

code-insidersコマンドをCUIから設定できないときの解決方法

以下のコマンドで設定できる。

ln -s "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code" "/usr/local/bin/code-insiders"

普通のvscodeの場合

ちなみにcodeコマンドも同じ方法で設定することができる。

ln -s "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" "/usr/local/bin/code"

メリット

PATHに追加せず設定できるため、ドキュメントに載っている方法と比較してこちらのほうはシェルを再読み込みする必要がないというメリットがある。

4
3
0

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
4
3