在 macOS 中从终端打开 Sublime Text [英] Open Sublime Text from Terminal in macOS

查看:77
本文介绍了在 macOS 中从终端打开 Sublime Text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在终端中使用 .subl

返回-bash: .subl: command not found

有人知道如何在 macOS 中从命令行打开 Sublime Text 3 吗?

Anyone know how to open Sublime Text 3 from the command line in macOS?

推荐答案

我终于让它在我的 OSX 机器上工作了.我使用以下步骤使其工作:

I finally got this to work on my OSX box. I used these steps to get it to work:

  1. 从您的 ST 安装中测试 subl:

首先,在终端中导航到您希望 ST 打开的小文件夹并输入以下命令:

First, navigate to a small folder in Terminal that you want ST to open and enter the following command:

 /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl .

注意:您可能需要将上面命令中的 Sublime Text.app 替换为 Sublime Text 3.appSublime Text 2.app 取决于应用程序在 Applications 目录中的存储位置.上述命令末尾的 . 将打开您所在的当前工作目录(再次确保您所在的目录仅包含几个文件!).

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!).

如果你没有让 Sublime Text 打开你当前的工作目录,那么接下来的步骤将不起作用.如果没有任何反应或者您从终端收到错误,那将是因为它找不到 Sublime Text 应用程序.这意味着您必须检查您输入的内容(拼写等)或未安装 Sublime Text!

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!

检查.bash_profile":

Check ".bash_profile":

现在是在 PATH 文件夹中创建符号链接的时候了,但是,在此之前,让我们使用 nano ~/.bash_profile 检查您的配置文件.这些是与 subl 在 Sublime Text 的命令行上工作有关的以下几行:

Now it's time to create your symbolic link in your PATH folder, BUT, before we do, let's check your profile file by using nano ~/.bash_profile. These are the following lines that pertain to having subl work on the command line for Sublime Text:

 export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH
 export EDITOR='subl -w'

第一行设置您希望终端在您的机器上查找二进制文件的位置,我将把我的符号链接存储在 /usr/local/bin 目录中 - 我猜你可以将它存储在任何地方,前提是您已通知终端在哪里查找二进制文件.

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.

第二行是可选的,只是将 Sublime Text 设置为默认编辑器.已添加标志 -w,您可以通过访问 Sublime Text 文档来了解有关标志的更多信息:ST4 sublST3 sublST2 subl

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: ST4 subl, ST3 subl or 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.

创建一个到 Sublime Text 的符号链接:

Create a symbolic link to Sublime Text:

现在在您选择的路径中(我使用了 /usr/local/bin),您现在输入以下命令:

Now in your chosen path (I used /usr/local/bin) you now enter the following command:

 ln -s /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl 与您在上述第 1 步中输入和验证的位置完全相同./usr/local/bin/subl 是您希望符号链接所在的位置 - 需要是上述第 2 步中的 PATH 位置之一.

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. The /usr/local/bin/subl being the location of where you want the symbolic link to be located - needs to be one of your PATH locations from STEP 2 above.

现在,当您导航到要在 Sublime Text 中打开的文件夹或文件时,现在只需输入 subl 后跟文件名或 . 即可打开当前工作目录.

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 . to open the current working directory.

这篇关于在 macOS 中从终端打开 Sublime Text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆