如何从OSX上的命令行打开Visual Studio代码?

时间:2015-04-30 14:56:53

标签: visual-studio-code

docs提到了一个名为code的可执行文件,但我不知道在哪里可以找到它,所以我可以把它放在我的路上。我从VSCode站点下载的zip不包含任何此类可执行文件。 (我能够运行.app就好了。)

这是仅限Windows吗?

29 个答案:

答案 0 :(得分:506)

来自Visual Studio Code Setup page

  

提示:如果你想通过输入'code'从终端运行VS Code,VS Code有一个命令Shell命令:在PATH中安装'code'命令,添加'代码' '到您的$ PATH变量列表。

     

安装完成后,启动VS Code。现在打开命令选项板(在Mac上为F1或 + + P )并键入shell command以查找{{1命令。

     

执行该命令后,重新启动终端以使新的$ PATH值生效。您只需输入“代码”即可。在任何文件夹中开始编辑该文件夹中的文件。

答案 1 :(得分:111)

  

⚡️TheEasy Solution。

  1. 下载,安装并打开Mac的Visual Studio Code
  2. 在Mac上打开命令选项板( + + P )或查看命令调色板
  3.   

    3.输入public class AlbumPlayActivity extends AppCompatActivity implements View.OnClickListener { private List<SongListModel> songs = new ArrayList<SongListModel>(); private SongAdapter songAdapter; String URL_SONGS; String URL_ALBUM_ART; String URL_ALBUM_ART_BIG; String URL_ALBUM_ART_BLUR; String URL_MP3; ListView lvSongs; MediaPlayer mediaPlayer; NetworkImageView nivAlbumArt,nivAlbumArtBlur; private double startTime = 0; private double finalTime = 0; private Handler myHandler = new Handler(); public int currentlyPlaying; private int forwardTime = 5000; private int backwardTime = 5000; private SeekBar seekbar; ImageLoader imageLoader = AppController.getInstance().getImageLoader(); public int oneTimeOnly = 0; int songID = 0; ImageButton ibPrev, ibPlay, ibPause, ibNext, ibFastForward, ibFastRewind; TextView tvStartTime, tvEndTime; RelativeLayout llList; ImageButton ibShare; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_album_play); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); URL_SONGS = getIntent().getExtras().getString("URL_SONG"); URL_ALBUM_ART = getIntent().getExtras().getString("URL_ALBUM_ART"); URL_ALBUM_ART_BIG = getIntent().getExtras().getString("URL_ALBUM_ART_BIG"); URL_ALBUM_ART_BLUR = getIntent().getExtras().getString("URL_ALBUM_ART_BLUR"); imageLoader = AppController.getInstance().getImageLoader(); lvSongs = (ListView) findViewById(R.id.lvSongList); nivAlbumArt = (NetworkImageView) findViewById(R.id.nivAlbumArt); ibNext = (ImageButton) findViewById(R.id.ibNext); ibPlay = (ImageButton) findViewById(R.id.ibPlay); ibFastRewind = (ImageButton) findViewById(R.id.ibFastRewind); ibFastForward = (ImageButton) findViewById(R.id.ibFastForward); ibPrev = (ImageButton) findViewById(R.id.ibPrev); seekbar = (SeekBar) findViewById(R.id.seekBar); tvStartTime = (TextView) findViewById(R.id.tvStartTime); tvEndTime = (TextView) findViewById(R.id.tvEndTime); llList = (RelativeLayout)findViewById(R.id.llList); ibShare = (ImageButton)findViewById(R.id.ibShare); seekbar.setClickable(false); ibNext.setOnClickListener(this); ibPlay.setOnClickListener(this); ibPrev.setOnClickListener(this); ibFastRewind.setOnClickListener(this); ibFastForward.setOnClickListener(this); ibShare.setOnClickListener(this); songAdapter = new SongAdapter(this, songs); lvSongs.setAdapter(songAdapter); loadSongs(); lvSongs.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { songs.get(songID).setVisible(false); songAdapter.notifyDataSetChanged(); songID = position; stopPlaying(); URL_MP3 = "http://your_host/apps/content/mp3/" + songs.get(position).getSong().replace(" ", "%20"); songs.get(songID).setVisible(true); mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mediaPlayer.setDataSource(URL_MP3); } catch (IOException e) { e.printStackTrace(); } mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.start(); ibPlay.setImageResource(R.drawable.ic_pause_circle_outline_white_48dp); finalTime = mp.getDuration(); startTime = mp.getCurrentPosition(); if (oneTimeOnly == 0) { seekbar.setMax((int) finalTime); oneTimeOnly = 1; } tvEndTime.setText(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) finalTime), TimeUnit.MILLISECONDS.toSeconds((long) finalTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime))) ); tvStartTime.setText(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) startTime), TimeUnit.MILLISECONDS.toSeconds((long) startTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) startTime))) ); seekbar.setProgress((int) startTime); myHandler.postDelayed(UpdateSongTime, 100); } }); mediaPlayer.prepareAsync(); } }); seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if(mediaPlayer != null && fromUser){ mediaPlayer.seekTo(progress); } } }); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.ibPrev: songs.get(songID).setVisible(false); songAdapter.notifyDataSetChanged(); songID--; if(songID<0){ songID=0; } if (songID >= 0) { startPlaying("http://..../apps/content/mp3/" + songs.get(songID).getSong().replace(" ", "%20")); songs.get(songID).setVisible(true); songAdapter.notifyDataSetChanged(); } break; case R.id.ibPlay: if (mediaPlayer.isPlaying()) { if (mediaPlayer != null) { mediaPlayer.pause(); Log.i("Status:", " Paused"); ibPlay.setImageResource(R.drawable.ic_play_circle_outline_white_48dp); } } else { if (mediaPlayer != null) { mediaPlayer.start(); Log.i("Status:", " Playing"); ibPlay.setImageResource(R.drawable.ic_pause_circle_outline_white_48dp); finalTime = mediaPlayer.getDuration(); startTime = mediaPlayer.getCurrentPosition(); if (oneTimeOnly == 0) { seekbar.setMax((int) finalTime); oneTimeOnly = 1; } tvEndTime.setText(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) finalTime), TimeUnit.MILLISECONDS.toSeconds((long) finalTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime))) ); tvStartTime.setText(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) startTime), TimeUnit.MILLISECONDS.toSeconds((long) startTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) startTime))) ); seekbar.setProgress((int) startTime); myHandler.postDelayed(UpdateSongTime, 100); } } break; case R.id.ibShare: Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "Welcome to music radio"); sendIntent.setType("text/plain"); startActivity(sendIntent); break; case R.id.ibNext: songs.get(songID).setVisible(false); songAdapter.notifyDataSetChanged(); songID++; if (songID==songs.size()){ ibNext.setEnabled(false); } if (songID <= songs.size()) { startPlaying("http://..../apps/content/mp3/" + songs.get(songID).getSong().replace(" ", "%20")); songs.get(songID).setVisible(true); songAdapter.notifyDataSetChanged(); } break; case R.id.ibFastForward: int temp = (int) startTime; if ((temp + forwardTime) <= finalTime) { startTime = startTime + forwardTime; mediaPlayer.seekTo((int) startTime); } else { Toast.makeText(getApplicationContext(), "Cannot jump forward 5 seconds", Toast.LENGTH_SHORT).show(); } break; case R.id.ibFastRewind: int temp1 = (int) startTime; if ((temp1 - backwardTime) > 0) { startTime = startTime - backwardTime; mediaPlayer.seekTo((int) startTime); } else { Toast.makeText(getApplicationContext(), "Cannot jump backward 5 seconds", Toast.LENGTH_SHORT).show(); } break; } } public void loadSongs() { JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(URL_SONGS, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { nivAlbumArt.setImageUrl(URL_ALBUM_ART_BIG, imageLoader); Glide.with(AlbumPlayActivity.this).load(URL_ALBUM_ART_BLUR).asBitmap().into(new SimpleTarget<Bitmap>(700,300) { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { Drawable drawable = new BitmapDrawable(resource); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { llList.setBackground(drawable); } } }); for (int i = 0; i < response.length(); i++) { try { JSONObject jObj = response.getJSONObject(i); SongListModel songModel = new SongListModel(); Log.i(">>REQ", jObj.toString()); songModel.setAlbum_id(jObj.getString("album_id")); songModel.setCategory_id(jObj.getString("category_id")); songModel.setId(jObj.getString("id")); songModel.setSinger_id(jObj.getString("singer_id")); songModel.setSong(jObj.getString("song")); songs.add(songModel); startPlaying(songID); songs.get(songID).setVisible(true); } catch (JSONException e) { e.printStackTrace(); } } songAdapter.notifyDataSetChanged(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }); jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy( (int) TimeUnit.SECONDS.toMillis(20), DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); AppController.getInstance().addToRequestQueue(jsonArrayRequest); } private void startPlaying(final int position) { stopPlaying(); mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mediaPlayer.setDataSource("http://..../apps/content/mp3/" + songs.get(position).getSong().replace(" ", "%20")); } catch (IOException e) { e.printStackTrace(); } mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.start(); currentlyPlaying = position; finalTime = mp.getDuration(); startTime = mp.getCurrentPosition(); ibPlay.setImageResource(R.drawable.ic_pause_circle_outline_white_48dp); if (oneTimeOnly == 0) { seekbar.setMax((int) finalTime); oneTimeOnly = 1; } tvEndTime.setText(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) finalTime), TimeUnit.MILLISECONDS.toSeconds((long) finalTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime))) ); tvStartTime.setText(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) startTime), TimeUnit.MILLISECONDS.toSeconds((long) startTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) startTime))) ); seekbar.setProgress((int) startTime); myHandler.postDelayed(UpdateSongTime, 100); } }); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { currentlyPlaying++; if(currentlyPlaying >= songs.size()) currentlyPlaying = 0; startPlaying(currentlyPlaying); } }); mediaPlayer.prepareAsync(); } private void stopPlaying() { if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.reset(); mediaPlayer.release(); mediaPlayer = null; myHandler.removeCallbacks(UpdateSongTime); } } @Override public void onBackPressed() { stopPlaying(); finish(); } @Override public boolean onCreateOptionsMenu (Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { stopPlaying(); finish(); return true; } if (id == R.id.action_home) { stopPlaying(); Intent intent = new Intent(AlbumPlayActivity.this,HomeActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); return true; } return super.onOptionsItemSelected(item); } private Runnable UpdateSongTime = new Runnable() { public void run() { startTime = mediaPlayer.getCurrentPosition(); seekbar.setProgress((int) startTime); tvStartTime.setText(String.format("%d:%d", TimeUnit.MILLISECONDS.toMinutes((long) startTime), TimeUnit.MILLISECONDS.toSeconds((long) startTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS. toMinutes((long) startTime))) ); myHandler.postDelayed(this, 100); } }; 进行查找   shell command

    1. 安装它,你就完成了
    2. 这是一个免费的GIF。

      Install Code on Command line

      之后,您可以在终端中使用Shell Command: Install 'code' command in PATH commandcode

      code .

      干杯!

答案 2 :(得分:31)

我们将脚本更新为以下语法以支持多个文件和文件夹作为参数,并修复了未正确检测当前工作目录的问题:

code () {
    VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}

我们的VS Code 1.0版本更新:

请使用命令面板中的Install 'Code' command in pathInstall 'code-insiders' command in path命令(View | Command Palette)使代码可用于命令行。

答案 3 :(得分:23)

如果要在terminal上打开Visual Studio Code上的文件或文件夹,iTerm等,则下面是安装Visual Studio代码时默认的命令

从命令行打开Visual Studio代码

code --

打开整个文件夹/目录

code .

打开特定文件

code file_name
eg:- code index.html

答案 4 :(得分:8)

我有一个~/bin/code shell脚本,与@BengaminPasero编写的命令相匹配。

#!/bin/bash
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*

我在~/bin:前加$PATH,这样我就可以在不污染~/.bash_profile脚本的情况下添加一堆关闭脚本。

答案 5 :(得分:6)

打开VSC并按(Command + Up + P)后,我尝试键入“ shell命令”,但没有任何反应。为了显示“ Shell命令:在PATH命令中安装'code'命令”,您必须执行以下操作:

  1. 按(Command,Up,P)

  2. 键入>(这将显示并运行命令)

  3. 然后输入Shell Command: Install 'code' command in PATH command。然后应该出现。

    一旦单击它,它就会更新,您应该一切顺利!

MacOS X Launch from Command Line docs

答案 6 :(得分:4)

这是我在该线程中寻找的教程。它显示了通过编写代码在Visual Studio Code中打开文件的方法。

1.-打开文件

重击

                open ~/.bash_profile 

终端操作系统

                    open ~/.zshrc

2.-在文件中添加:

         code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}

3.-重新初始化终端,然后尝试打开要打开的文件夹

         code .

4.-然后,您可以按此注释所示使用它:https://stackoverflow.com/a/41821250/10033560

答案 7 :(得分:3)

在OSX Mavericks上,我在vscode中创建了一个名为.bashrc的bash脚本(改编自VSCode Setup中的~/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>现在按预期工作。

答案 8 :(得分:3)

对于Macbook Book Pro 2019 MacOS版本10.15.6上的我来说,在VSCode中打开命令面板的快捷方式是Shift + Command + P

在打开它时,只需写install code,然后按enter

enter image description here

之后,只需打开终端并输入code,您的vscode将开始打开。

答案 9 :(得分:2)

  

注意:仅适用于Windows用户。

许多人已经建议使用code .命令从命令提示符打开代码的方法。这只会打开 Visual Studio Code Stable 构建。但是,如果您已下载 Visual Studio Code Insider 构建/版本(具有所有最新的构建/功能,但版本不稳定),则需要按照以下Windows中的说明进行操作:

  • 转到“控制面板\系统和安全性\系统”。点击高级系统设置 enter image description here
  • 单击环境变量 enter image description here
  • 在“系统变量”选项卡下,单击“编辑”以获取路径变量 enter image description here
  • 添加路径C:\Users\tsabu\AppData\Local\Programs\Microsoft VS Code Insiders\bin (或) C:\Program Files\Microsoft VS Code Insiders\bin基于您在计算机中安装vscode内部人员的位置。 enter image description here

    打开 new 命令提示符,然后键入code-insiders .以打开vscode-insider 构建/版本

答案 10 :(得分:2)

如果在下载文件夹中安装vs代码,则需要将VS代码移至Application文件夹,然后打开vs代码,然后按shift + command + p之后,您将看到enter image description here下图。然后,您需要输入code .,现在您可以使用了。

答案 11 :(得分:2)

尝试这个

打开Visual Studio代码,然后按Command + Shift + P,然后在命令面板中键入Shell,现在您可以找到此选项,例如Shell Command:从命令面板的建议列表中的PATH中安装代码。选择该选项。

通过终端/命令提示符打开VSCode

就是这样。

现在打开您的终端类型。

$代码。

答案 12 :(得分:2)

我发现了mingw32的一个简洁的解决方法(即对于那些使用由git-scm.com在windows上安装的bash版本的人):

code () { VSCODE_CWD="$PWD" cmd //c code $* ;}

答案 13 :(得分:2)

如果您使用的是 VS Code Insiders

code-insiders .

如果您使用的是 VS代码

code .

答案 14 :(得分:1)

您可以使用Visual Studio Code defines

vscode:协议
open vscode://file/full/path/to/project/or/file

您也可以使用

/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code

如果你不喜欢modifying your path

答案 15 :(得分:1)

由于VS Code Insiders,我遇到了这个问题。 路径变量在那里,但我需要将code-insiders.cmd重命名为code.cmd。

也许这对某人有用。

答案 16 :(得分:1)

如果您使用 visual code insiders 并且想从终端或任何其他命令行工具在 Visual Studio Code insider 中打开文件或文件夹,那么您可以参考以下默认命令visual studio code insider 内。

从命令行打开 Visual Studio Code

code-insiders --

打开整个文件夹/目录

code-insiders .

打开特定文件

code-insiders file_name

例如:- 代码 index.html

答案 17 :(得分:1)

非常简单:

从命令行启动

您还可以通过在终端上输入“代码”后在终端上运行VS Code:

启动VS代码。 打开命令面板(⇧⌘P),然后键入“ shell命令”以找到Shell命令:在PATH命令中安装“ code”命令。

https://code.visualstudio.com/docs/setup/mac

答案 18 :(得分:1)

这就是在Mac OS Catalina上对我有用的功能-发现here(谢谢,乔西亚!)

如果您使用的是Mac OS Catalina,则需要编辑.zprofile而不是.bash_profile。

  1. 编辑您的〜/ .zprofile文件:vim ~/.zprofile
  2. 在其单独的行中添加以下代码:code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
  3. 保存文件::wq
  4. 重新运行更新的文件:source ~/.zprofile
  5. 测试运行code .会在VS Code中打开您当前的文件夹!

答案 19 :(得分:0)

VSCode 现在支持它开箱即用的 with version 1.58。只需输入:

$ cd path/to/your/directory
$ code .

答案 20 :(得分:0)

VS Code Command Line处发出的用于启动路径的指令不正确;示例中显示的前导冒号不起作用。但是,使用反斜杠终止目录名称启动会按预期打开指定的目录。

所以,例如,

  

代码C:\ Users \ DAVE \ Documents \ Programming \ Angular \ StringCalculator \ src \

在目录C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src中打开Visual Studio代码编辑器。

重要事项:终端反斜杠虽然是可选的,但很有用,因为它清楚地表明打算打开目录,而不是文件。请记住文件名 extensions 是,并且始终是可选的。

注意:附加到PATH列表的目录是\bin目录,shell命令code启动 Windows NT命令脚本

因此,当合并到另一个shell脚本中时,code必须调用启动,如果您希望脚本的其余部分运行。值得庆幸的是,我在第一次测试我正在创建的新shell脚本之前发现了这一点,以便在本地Web服务器,默认Web浏览器和Visual Studio Code中同时启动Angular 2项目。

以下是我的Angular启动脚本,适用于消除对我在其他地方发布但未严格要求的系统实用程序的依赖。

@echo off

转到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.
=======================================================================

:SKIPREM

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

答案 21 :(得分:0)

就我而言,我不得不使用别名:

alias code="/<PATH TO VSCODE>/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"

您可以在您的 ~/.bash_profile 中添加此别名。

答案 22 :(得分:0)

对于 Windows,您可以使用命令:

start Code filename.extension

以上行对我有用。

答案 23 :(得分:0)

如果使用snap安装VS CODE。您将需要在PATH环境变量中添加/snap/bin。 因此,请打开您的.bashrc.zshrc 并在您的PATH环境变量中添加/snap/bin

重新加载终端, 并且code comand将启动它

答案 24 :(得分:0)

将您当前的文件夹链接到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 ."

答案 25 :(得分:0)

将此添加到 / usr / local / bin / code ,如果路径不同,则可能需要修改路径。

#app/admin/employees.rb
filter :month, :as => :select, :collection => (1..12)

#app/models/employee.rb
scope :month_eq, ->(month) { where('MONTH(birthday) = ?', month.to_i) } # for MySQL

def self.ransackable_scopes(_auth_object = nil)
  [:month_eq]
end

之后制作可执行文件

#!/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 $?

答案 26 :(得分:0)

对于Windows用户 只需输入

即可
>code .

这里有更多命令 https://code.visualstudio.com/docs/editor/command-line

答案 27 :(得分:0)

我跑了:open -a "Visual Studio Code" [folder-name]用我的Visual Studio Code应用程序打开一个文件夹。如果您只想打开应用程序,则文件夹名称是可选的。不确定这是否完全是你的用例,但希望这有帮助!

答案 28 :(得分:-1)

$> open -a "Visual Studio Code" [文件名]