更新
正如 Tony 在 cmets 中指出的那样,Atom Shell 已重命名为 Electron。
我更新后的代码应该是:
code() { (/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron "$1" &) }
另外,我建议使用official way,如Benjamin's answer 中所述:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*; }
您应该在~/.bash_profile 文件中创建一个命令来启动编辑器。每次打开终端并启动 bash 会话时都会读取此文件。
由于该进程应该在后台启动,并且我们想要传递一个目录或文件作为参数,我会将这样的单行函数添加到.bash profile:
code() { (/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Atom "$1" &) }
/Applications/Visual\ Studio\ Code.app 是指向 Visual Studio Code 应用的路径。如果您将其安装在其他地方,则可能需要对其进行调整。
此函数打开作为 Visual Studio Code 基础的 Atom 编辑器,并将第一个参数通过 $1 扩展传递给它。 Ampersand & 将使进程与终端分离并在后台运行。整个函数体放在方括号 () 中,以消除有关分离和结束进程的消息。
如果您的系统上缺少.bash_profile 文件,您必须先创建它。
编辑文件后,您必须重新启动当前的 bash 会话。