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

查看:198
本文介绍了在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 .

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

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,则接下来的步骤将不起作用.如果什么也没发生,或者您从Terminal收到错误消息,那是因为它找不到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文档来找到有关标志的更多信息: ST2子

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 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是您要放置符号链接的位置-必须是上述STEP 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天全站免登陆