本文翻译自:Open Sublime Text from Terminal in macOS
In Terminal when I use .subl
在终端中,当我使用.subl
It returns -bash: .subl: command not found
它返回-bash: .subl: command not found
Anyone know how to open Sublime Text 3 from the command line in macOS? 有人知道如何从macOS的命令行中打开Sublime Text 3吗?
#1楼
参考:https://stackoom.com/question/15yFZ/在macOS中从终端打开Sublime-Text
#2楼
if you have subl set up to be called from the command line, the proper command to open the current directory is: 如果已设置要从命令行调用的subl,则打开当前目录的正确命令是:
subl .
" OS X Command Line " is a link on how to make sure everything is set up. “ OS X命令行 ”是有关如何确保所有设置均已设置的链接。
#3楼
I finally got this to work on my OSX box. 我终于可以在OSX盒子上使用它了。 I used these steps to get it to work: 我使用以下步骤使其正常工作:
Test
subl
from your ST installation: 从ST安装中测试subl
:First, navigate to a small folder in Terminal that you want ST to open and enter the following command: 首先,在终端中导航到要ST打开的小文件夹,然后输入以下命令:
/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl .
NOTE: You may need to replace
Sublime\\ Text.app
in the command above toSublime\\ Text\\ 3.app
orSublime\\ Text\\ 2.app
depending upon where the application is stored in yourApplications
directory. 注意:您可能需要在上面的命令Sublime\\ Text.app
替换为Sublime\\ Text\\ 3.app
或Sublime\\ Text\\ 2.app
具体取决于应用程序在Applications
目录中的存储位置。 The.
的.
at the end of the above command opens the current working directory you are located in (again make sure you're in a directory that only contains a few files!). 在以上命令的末尾,将打开您所在的当前工作目录(再次确保您位于仅包含几个文件的目录中!)。If you DO NOT get Sublime Text opening your current working directory then the next set of steps will NOT work. 如果您没有在打开当前工作目录时看到Sublime Text,则接下来的步骤将不起作用。 If nothing happens or you get an error from Terminal it will be because it couldn't find the Sublime Text application. 如果什么也没发生,或者您从Terminal收到错误消息,那是因为它找不到Sublime Text应用程序。 This would mean that you would have to check what you've typed (spelling, etc.) OR that Sublime Text isn't installed! 这意味着您将必须检查您键入的内容(拼写等),或者未安装Sublime Text!
Check ".bash_profile": 检查“ .bash_profile”:
Now it's time to create your symbolic link in your
PATH
folder, BUT, before we do, let's check your profile file by usingnano ~/.bash_profile
. 现在是时候在PATH
文件夹BUT中创建符号链接了,在此之前,让我们使用nano ~/.bash_profile
检查您的配置文件。 These are the following lines that pertain to havingsubl
work on the command line for Sublime Text: 这些是与在Sublime Text的命令行上使subl
工作有关的以下行:export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH export EDITOR='subl -w'
The first line sets the location where you want Terminal to look for binaries on your machine, I'm going to store my symbolic link in the
/usr/local/bin
directory - I guess you could store it anywhere provided you've notified Terminal where to look for binaries. 第一行设置您希望终端在计算机上查找二进制文件的位置,我将把符号链接存储在/usr/local/bin
目录中-我猜您可以将其存储在通知终端的任何位置在哪里寻找二进制文件。The second line is OPTIONAL and just sets Sublime Text as the default editor. 第二行是OPTIONAL,仅将Sublime Text设置为默认编辑器。 The flag
-w
has been added and you can find out more about flags by going to the Sublime Text docs: ST3 subl or ST2 subl 标志-w
已添加,您可以通过转到Sublime Text文档: ST3 subl或ST2 subl来找到有关标志的更多信息。If you do make any edits to this file once you have closed it, you need to run the command: 如果您在关闭文件后确实对其进行了任何编辑,则需要运行以下命令:
source ~/.bash_profile
to compile your newly applied edits. 来编译您新应用的修改。 If you see any errors after sourcing your file get them fixed before moving to the final step. 如果在采购文件后看到任何错误,请先进行修复,然后再进行最后一步。
Create a symbolic link to Sublime Text: 创建一个符号链接到Sublime Text:
Now in your chosen path (I used
/usr/local/bin
) you now enter the following command: 现在在您选择的路径(我使用/usr/local/bin
)中,输入以下命令:ln -s /Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
The
/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl
being EXACTLY the same location as what you entered and verified as working in STEP 1 above./Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl
与上述步骤1中输入并验证为可以使用的位置完全相同。 The/usr/local/bin/subl
being the location of where you want the symbolic link to be located - needs to be one of yourPATH
locations from STEP 2 above./usr/local/bin/subl
是您希望符号链接位于的位置-必须是上述STEP 2中的PATH
位置之一。Now when you navigate to a folder or file that you want to open in Sublime Text you now just enter
subl
followed by the name of the file or.
现在,当您导航到要在Sublime Text中打开的文件夹或文件时,现在只需输入subl
然后输入文件名或即可.
to open the current working directory. 打开当前工作目录。
#4楼
This worked for me (I'm using OS X Mavericks) 这对我有用(我正在使用OS X Mavericks)
First, create a symbolic link: 首先,创建一个符号链接:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl
Now you can open sublime with 现在您可以打开
subl "/a/path/to/the/directory/you/want/to/open"
#5楼
For MAC 10.8+: 对于MAC 10.8+:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
worked. 工作了。
#6楼
I'm using oh-my-zsh on Mac OSX Mavericks and the symbol link didn't work for me, so I added an alias in my .zshrc file instead: 我在Mac OSX Mavericks上使用oh-my-zsh,符号链接对我不起作用,因此我在.zshrc文件中添加了一个别名:
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
Open a new terminal and you should be good to go, and type subl
. 打开一个新的终端,您应该subl
顺利,然后输入subl
。