回答:
ヒント:単に「コード」と入力してターミナルからVSコードを実行する場合、VSコードにはコマンドがあります。シェルコマンド:「コード」コマンドをPATHにインストールして、「コード」を$ PATH変数リストに追加します。
インストール後、VS Codeを起動します。次に、コマンドパレット(F1またはMacの⇧+ ⌘+ P)を開き、コマンドを入力
shell command
しますShell Command: Install 'code' command in PATH
。コマンドを実行した後、ターミナルを再起動して新しい$ PATH値を有効にします。単純に「コード」と入力できます。フォルダ内のファイルの編集を開始します。
code -r <filename>
。通常、それはあなたが望むものです。
code
ラップトップを再起動した後、コマンドでVisual Studio Codeを起動できません。
/usr/local/bin/code
という一時リンクの実行可能ファイルにリンクするというシンボリックリンクを作成します/private/var/folders
。コンピュータを再起動すると、そのディレクトリが削除され、シンボリックリンクが消えます。私はより永続的なシンボリックリンクを作りました:sudo ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/code
。これが/usr/local/bin
あなたの中にあると仮定すると、PATH
これは再起動後も存続します。
⚡️簡単なソリューション。
🌟3.入力
shell command
して検索Shell Command: Install 'code' command in PATH command
📟こちらが無料のGIFです。
その後、code
またはcode .
ターミナルで使用できます。
code
平和!✌️
もう少し進んでVSCode CLIを使用するためのいくつかの優れたヒント/トリックを学びたい場合は、私のワークフローに関する無料のビデオを公開しました。
その後、スクリプトを次の構文に更新して、引数として複数のファイルとフォルダーをサポートし、現在の作業ディレクトリが正しく検出されない問題を修正しました。
code () {
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}
VS Code 1.0リリースの更新:
コマンドを使用するInstall 'Code' command in path
かInstall 'code-insiders' command in path
、コマンドパレット(View | Command Palette
)からコードをコマンドラインで使用できるようにしてください。
sudo code
ますか?VSCodeを使用して一部のNPMモジュールで作業していますが、上書きするにはsudoが必要です。
~/bin/code
@BengaminPaseroが書いたコマンドに一致するシェルスクリプトがあります。
#!/bin/bash
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
接頭辞~/bin:
my を付けると、$PATH
スクリプトを汚染することなく、1回限りのスクリプトの束を追加でき~/.bash_profile
ます。
function code { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* }
これは私がこのスレッドで探していたチュートリアルでした。コードを記述してVisual Studio Codeでファイルを開く方法を示します。
1.-ファイルを開く
バッシュ
open ~/.bash_profile
端末OS
open ~/.zshrc
2.-ファイルに以下を追加します:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
3.-端末を再初期化し、開きたいフォルダで試してください
code .
4.-次に、このコメントに示すようにそれを使用できます:https ://stackoverflow.com/a/41821250/10033560
VSCを開いて(Command + Up + P)を押した後、「shell command」と入力してみましたが何も表示されませんでした。「Shell Command:Install 'code' command in PATH command」を表示するには、次の手順を実行する必要があります。
押す(コマンド、上、P)
タイプ>
(コマンドを表示して実行します)
次にと入力しShell Command: Install 'code' command in PATH command
ます。その後、表示されます。
クリックすると更新されます。これで問題ありません。
OSXでマーベリックス私は名前のbashスクリプト作成vscode
(から適応.bashrc
でVSCodeセットアップで)~/bin
:
#!/bin/bash
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
[[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
open -a "Visual Studio Code" --args "$F"
fi
vscode <file or directory>
期待どおりに動作するようになりました。
注:Windowsユーザーのみ。
多くの人々はすでに、コマンドを使用してコマンドプロンプトからコードを開く方法を提案していますcode .
。これにより、Visual Studio Code Stable ビルドのみが開きます。ただし、Visual Studio Code Insiderのビルド/バージョン(すべての最新のビルド/機能はあるが、不安定なバージョンがある)をダウンロードした場合は、Windowsで以下の手順に従う必要があります。
C:\Users\tsabu\AppData\Local\Programs\Microsoft VS Code Insiders\bin
(または)
追加C:\Program Files\Microsoft VS Code Insiders\bin
します。
開き、新しいプロンプトのコマンドを入力し、オープンvscode-インサイダービルド/バージョンにcode-insiders .
私はmingw32のきちんとした回避策を発見しました(つまり、git-scm.comによってWindowsにインストールされているバージョンのbashを使用している方):
code () { VSCODE_CWD="$PWD" cmd //c code $* ;}
cd /c/some/path
、code .
毎回自動的に設定する場合は、git bashを実行して追加します~/.bash_profile
Visual Studio Codeが定義するvscode:
プロトコルを使用できます。
open vscode://file/full/path/to/project/or/file
あなたも使うことができます
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code
パスを変更したくない場合
とてもシンプルです:
コマンドラインから起動する
パスに追加した後で「code」と入力して、ターミナルからVS Codeを実行することもできます。
VS Codeを起動します。コマンドパレット(⇧⌘P)を開き、「shell command」と入力して、シェルコマンドを見つけます。PATH コマンドで「コード」コマンドをインストールします。
ソース
これを/ usr / local / bin / codeに追加しました。パスが異なる場合は、パスの変更が必要になる場合があります。
#!/usr/bin/env bash
CONTENTS="/Applications/Visual Studio Code.app/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?
後で実行可能にする
sudo chmod +x /usr/local/bin/code
$CONTENTS/Resources/app/out/cli.js
自体を開くことに気づきました。CLIへの参照を削除すると、期待どおりに動作します。
私が実行しました:open -a "Visual Studio Code" [folder-name]
Visual Studio Codeアプリケーションでフォルダーを開きます。アプリケーションを開くだけの場合は、フォルダ名はオプションです。これがまさにあなたのユースケースかどうかはわかりませんが、これが役立つことを願っています!
パスを起動するためのVSコードコマンドラインでの指示が正しくありません。例に示されている先頭のコロンは機能しません。ただし、バックスラッシュで終了するディレクトリ名で起動すると、指定したディレクトリが期待どおりに開きます。
したがって、たとえば、
コードC:\ Users \ DAVE \ Documents \ Programming \ Angular \ StringCalculator \ src \
ディレクトリでVisual Studio Codeエディターを開きますC:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src
。
重要:端末のバックスラッシュは、オプションではありますが、ファイルではなくディレクトリを開くことを意図しているため、便利です。ファイル名拡張子はオプションであり、常にそうであることに注意してください。
注意: PATHリストに追加される\bin
ディレクトリはディレクトリであり、シェルコマンドcode
はWindows NTコマンドスクリプトを起動します。
したがって、別のシェルスクリプトに組み込む場合、スクリプトの残りの部分が実行さcode
れると予想される場合は、呼び出すか、起動する必要があります。ありがたいことに、ローカルWebサーバー、デフォルトのWebブラウザー、およびVisual Studio Codeで一度にAngular 2プロジェクトを開始するために作成する新しいシェルスクリプトの最初のテストの前に、これを発見しました。
以下は、他の場所で公開されているが厳密には必須ではないシステムユーティリティの1つへの依存を排除するように適合されたAngular起動スクリプトです。
@echo off
Goto SKIPREM
=========================================================================
Name: StartAngularApp.CMD
Synopsis: Start the Angular 2 application installed in a specified
directory.
Arguments: %1 = OPTIONAL: Name of directory in which to application
is installed
Remarks: If no argument is specified, the application must be in
the current working directory.
This is a completely generalized Windows NT command
script (shell script) that uses the NPM Angular CLI to
load an Angular 2 application into a Node development
Web server, the default Web browser, and the Visual
Studio Code text editor.
Dependencies: Unless otherwise specified in the command line, the
application is created in the current working directory.
All of the following shell scripts and programs must be
installed in a directory that is on the Windows PATH
directory list.
1) ShowTime.CMD
2) WWPause.exe
3) WWSleep.exe
4) npm (the Node Package Manager) and its startup
script, npm.cmd, must be accessible via the Windows
PATH environment string. By default, this goes into
directory C:\Program Files\nodejs.
5) The Angular 2 startup script, ng.cmd, and the Node
Modules library must be installed for global access.
By default, these go into directory %AppData%\npm.
Author: David A. Gray
Created: Monday, 23 April 2017
-----------------------------------------------------------------------
Revision History
-----------------------------------------------------------------------
Date By Synopsis
---------- --- --------------------------------------------------------
2017/04/23 DAG Script created, tested, and deployed.
=======================================================================
:スキップレム
echo BOJ %~0, version %~t0
echo.
echo -------------------------------------------------------
echo Displaying the current node.js version:
echo -------------------------------------------------------
echo.
node -v
echo.
echo -------------------------------------------------------
echo Displaying the current Node Package Manager version:
echo -------------------------------------------------------
echo.
call npm -v
echo.
echo -------------------------------------------------------
echo Loading Angular starter application %1
echo into a local Web server, the default Web browser, and
echo the Visual Studio Code text editor.
echo -------------------------------------------------------
echo.
if "%1" neq "" (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %1
echo -------------------------------------------------------
echo.
cd "%~1"
call code %1\src\
) else (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %CD%
echo -------------------------------------------------------
echo.
call code %CD%\src\
)
call ng serve --open
echo.
echo -------------------------------------------------------
echo %~nx0 Done!
echo -------------------------------------------------------
echo.
Pause
現在のフォルダーをvscodeにリンクします。
Windows Registry Editor Version 5.00
; Directory\Background\shell => on empty space
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
"Icon"="C:\\current-folder-vscode\\Code.exe,0"
@="VsCode"
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
@="C:\\current-folder-vscode\\Code.exe ."
; Directory\shell => on a folder
[HKEY_CLASSES_ROOT\Directory\shell\vscode]
@="VsCode"
"Icon"="C:\\current-folder-vscode\\Code.exe,0"
[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
@="C:\\current-folder-vscode\\Code.exe ."
これはMac OSカタリナで私にとってうまくいったものです- ここにあります (ありがとう、ジョサイア!)
Mac OSカタリナを使用している場合は、.bash_profileではなく.zprofileを編集する必要があります。
vim ~/.zprofile
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
source ~/.zprofile
。code .
すると、VS Codeで現在のフォルダーが開くことをテストします。
cmd+shift+P
):シェルコマンドを入力してシェルコマンドを検索:PATHコマンドに「コード」コマンドをインストール