在终端中使用。subl
它返回-bash: .subl:命令未找到
有人知道如何在macOS的命令行打开Sublime Text 3吗?
在终端中使用。subl
它返回-bash: .subl:命令未找到
有人知道如何在macOS的命令行打开Sublime Text 3吗?
当前回答
你可以添加一个别名
alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
然后你就可以打开文件夹了
subl <path>
其他回答
这是为了让它作为一个别名工作,而不是一个符号链接!
这将允许您在终端中运行额外的命令,而不会中断子会话。使用这里的许多符号链接答案(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.
我在终端中只用一行就实现了这一点(使用Sublime 3):
alias subl='/usr/local/bin/sublime'
Sublime Text 3文档中的Symlink命令将无法工作,因为在Mac OS X El Capitan或更高版本的Home位置中没有~/bin/目录。
因此,我们需要将符号链接放在/usr/local/bin上,因为在大多数情况下,这个路径将在我们的$ path变量中。
因此,下面的命令应该可以做到这一点:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
一旦你正确地创建了符号链接,你就可以像这样运行Sublime Text 3: subl。(。表示当前目录)
我使用的是Oh-My-Zshell,之前的别名对我来说不起作用,所以我写了一个简单的bash函数,允许您通过使用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
除非真的需要,否则不应该污染/usr/bin目录。 对于那些不受分发包管理器管理的二进制文件,我总是使用/usr/local/bin。为什么?因为如果包管理器更新了,它总是会替换/usr/bin中的文件。
我要做的是
sudo ln -s /Applications/Sublime\ Text。应用程序/内容/ SharedSupport / bin / subl /usr/local/bin/subl