在终端中使用。subl
它返回-bash: .subl:命令未找到
有人知道如何在macOS的命令行打开Sublime Text 3吗?
在终端中使用。subl
它返回-bash: .subl:命令未找到
有人知道如何在macOS的命令行打开Sublime Text 3吗?
当前回答
亲密的崇高。执行该命令。它会卸载它。你不会失去你的偏好。然后再运行一次。它将自动绑定subl。
brew install Caskroom/cask/sublime-text
其他回答
我将使用的方法非常简单。
open -a "sublime text" [file]
这就打开了崇高的文本。您可以指定要打开的文件作为可选参数,例如在当前目录中打开“myfile.txt”。
对于Sublime 4+,使用Bash甚至更简单:
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.bash_profile
这是为了让它作为一个别名工作,而不是一个符号链接!
这将允许您在终端中运行额外的命令,而不会中断子会话。使用这里的许多符号链接答案(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.
从macOS Catalina(10.15版本)开始使用zsh。为了允许Sublime从命令行运行,在你的主目录中编辑.zshrc(不带参数的cd会让你到达那里),并添加以下行:
export PATH="$PATH:/Applications/Sublime Text.app/Contents/SharedSupport/bin"
使用subl [filename]从命令行运行Sublime Text
有一个简单的方法。它只需要几个步骤,您不需要过多地使用命令行。如果你刚接触命令行,这是一种方法。
步骤1:找到要放入子可执行文件的bin文件
打开终端 输入CD ..--------------------- 这将返回一个目录 键入ls ------------------------ 看到一个目录中的文件列表 输入CD ..--------------------- 直到你得到一个包含usr文件夹 输入open usr ---------------,这应该会打开finder,你应该会看到一些文件夹 打开bin文件夹-------,这是你复制崇高的可执行文件的地方。
步骤2:查找可执行文件
打开finder 在文件下打开一个新的查找器窗口(CMD + N) 导航到应用程序文件夹 找到Sublime Text并右键单击,这样你就会得到一个下拉菜单 单击“显示包内容” 打开Content/SharedSupport/bin 复制subl文件 将它粘贴到我们之前找到的usr文件夹中的bin文件夹中 在subl --------------的终端类型中,这应该会打开Sublime Text
确保它被复制,而不是一个快捷方式。如果您确实有问题,请将usr/bin文件夹视为图标,并将subl粘贴到文件夹的空白区域。它不应该在图标图像中有一个快捷箭头。