当我在终端中使用.subl
命令时,会返回-bash: .subl: command not found
。
有人知道如何在macOS的命令行中打开Sublime Text 3吗?
当我在终端中使用.subl
命令时,会返回-bash: .subl: command not found
。
有人知道如何在macOS的命令行中打开Sublime Text 3吗?
除非你确实需要,否则不应该污染/usr/bin目录。
我总是使用/usr/local/bin来存放那些没有受到发行版软件包管理器控制的二进制文件。为什么呢?因为如果软件包管理器更新了,它会始终替换/usr/bin中的文件。
所以我会这样做:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
这个答案适用于 Mac OS Ventura 和 Sublime Text 4 (build 4143),它打破了通常的将<APP_PATH>/bin/subl
软链接到/usr/local/bin
的方法。
一个干净简单的解决方案是使用alias
. 在任何相关文件中,如:~/.zshrc
或~/.zprofile
添加:
alias subl="open -a /Applications/Sublime\ Text.app/Contents/MacOS/sublime_text"
然后,source ~/.zshrc
。
命令subl
应该可以工作。
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile
运行良好。
这是让它作为别名而工作,而不是符号链接!
这将允许您在终端中运行附加命令,而不会中断subl会话。使用这里的众多符号链接答案(ln -s
),会导致终端进程在使用Sublime文本时持续存在。如果您想要分离,可以在Bash配置文件中创建一个别名,如下所示:
Test subl
from your ST installation:
First, navigate to a folder in Terminal that you want ST to open and enter the following command:
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl .
NOTE: You may need to replace Sublime\ Text.app
in the command above to Sublime\ Text\ 3.app
or Sublime\ Text\ 2.app
depending upon where the application is stored in your Applications
directory. 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. If nothing happens or you get an error from Terminal it will be because it couldn't find the Sublime Text application. This would mean that you would have to check what you've typed (spelling, etc.) OR that Sublime Text isn't installed!
Check and update ".bash_profile":
Now add the alias in your Bash Profile. Open it via vim ~/.bash_profile
. These are the following lines that pertain to having subl
work on the command line for Sublime Text:
## For Sublime Text 3 alias
alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
## For Sublime Text global editor preference **Optional
export EDITOR='subl -w'
I suggest always commenting your code in here with ##
. The second line is OPTIONAL and just sets Sublime Text as the default editor. 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
If you do make any edits to this file once you have closed it, you need to source
this file in your current session or close the terminal (tab) and open a new one. You can source
this file by running the command source ~/.bash_profile
Resolve any errors before moving to the final step.
如果您想在Mac终端中使用Sublime打开文件
open 'path/file.txt' -a '/Applications/Sublime Text.app'
我正在使用Mac Airbook,请打开终端并输入以下命令:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl
subl index.py
我可以在终端中只用一行命令(使用Sublime 3)来实现这个:
alias subl='/usr/local/bin/sublime'
我建议如果你是从Sublime Text 2升级过来的话,在按照上述步骤之前,先进入/usr/bin并删除旧的subl。这个升级是值得的。
总结一下不同的方法:
open /Applications/Sublime\ Text.app/
open -a /Applications/Sublime\ Text.app/ myFileToOpen.txt
通过创建一个名为“sublime”的新别名来缩短您的命令,并使用它
a. 打开bash_profile:
nano ~/.bash_profile
b. 复制此行以创建别名并保存并重新启动终端
alias sublime="open -a /Applications/Sublime\ Text.app"
c. 用法:使用sublime text打开apple.txt(如果需要,请提供文件路径)
sublime apple.txt
sublime
从命令行打开当前文件夹中的Sublime编辑器。还可以指定要从编辑器中打开的文件。# Open Sublime from current folder or specified folder
sublime(){
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl ./$1
}
使用方法:在终端中打开当前文件夹:
$ sublime
打开特定文件夹的用法:
$ sublime path/to/the/file/to/open
subl
的问题。我已经在/usr/local/bin/subl
创建了符号链接,它指向/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
。我甚至在我的~/.bash_profile
中添加了export PATH=/usr/local/bin:$PATH
和export EDITOR="subl -w"
,但它仍然无法正常工作,并且我收到相同的错误提示。 - rs77Angelfirenze$ /Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl ; exit; logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed. [Process completed]
Sublime Text 3最终在新会话中打开。我已经安装了Homebrew并按照说明进行了操作。 - Angelfirenzefile.txt
,可以使用命令open -a "Sublime Text" file.txt
更适合。这将使用Sublime Text打开指定的文本文件,而不需要手动打开软件后再打开文件。 - mareoraft.subl
,而是subl
。 - the Tin Man.bash_profile
文件后,请确保关闭终端并重新打开。这是唯一真正帮助我的方法。我想确保没有人会被卡在这个明显但非常重要的步骤上^^ - SHANNAX