在终端中使用。subl

它返回-bash: .subl:命令未找到

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


当前回答

下面的方法对我很有效

open -a Sublime\ Text file_name.txt
open -a Sublime\ Text Folder_Path

您可以使用别名使事件简单,如

在您的

~ / . bash_profile

alias sublime="open -a Sublime\ Text $@"

那么下次你可以使用下面的命令打开文件/文件夹

sublime file_name.txt
sublime Folder_Path

其他回答

有一个简单的方法。它只需要几个步骤,您不需要过多地使用命令行。如果你刚接触命令行,这是一种方法。

步骤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粘贴到文件夹的空白区域。它不应该在图标图像中有一个快捷箭头。

根据Sublime的设置文档

echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile

工作很好。

我将使用的方法非常简单。

open -a "sublime text" [file]

这就打开了崇高的文本。您可以指定要打开的文件作为可选参数,例如在当前目录中打开“myfile.txt”。

在默认路径下创建文件对我来说不能作为菜单。Sublime-menu文件几乎覆盖了所有其他菜单选项,只留下一个自定义菜单。

对我来说有用的是在~/Library/Application Support/Sublime Text 3/Packages/User/Main路径下创建以下文件。sublime-menu(注意用户目录而不是默认目录):

[
    {
        "caption": "File",
        "mnemonic": "F",
        "id": "file",
        "children":
        [
            {
                "caption": "Open Recent More",
                "children":
                [
                    { "command": "open_recent_file", "args": {"index": 1 } },
                    { "command": "open_recent_file", "args": {"index": 2 } },
                    { "command": "open_recent_file", "args": {"index": 3 } },
                    { "command": "open_recent_file", "args": {"index": 4 } },
                    { "command": "open_recent_file", "args": {"index": 5 } },
                    { "command": "open_recent_file", "args": {"index": 6 } },
                    { "command": "open_recent_file", "args": {"index": 7 } },
                    { "command": "open_recent_file", "args": {"index": 8 } },
                    { "command": "open_recent_file", "args": {"index": 9 } },
                    { "command": "open_recent_file", "args": {"index": 10 } },
                    { "command": "open_recent_file", "args": {"index": 11 } },
                    { "command": "open_recent_file", "args": {"index": 12 } },
                    { "command": "open_recent_file", "args": {"index": 13 } },
                    { "command": "open_recent_file", "args": {"index": 14 } },
                    { "command": "open_recent_file", "args": {"index": 15 } },
                    { "command": "open_recent_file", "args": {"index": 16 } },
                    { "command": "open_recent_file", "args": {"index": 17 } },
                    { "command": "open_recent_file", "args": {"index": 18 } },
                    { "command": "open_recent_file", "args": {"index": 19 } },
                    { "command": "open_recent_file", "args": {"index": 20 } },
                    { "command": "open_recent_file", "args": {"index": 21 } },
                    { "command": "open_recent_file", "args": {"index": 22 } },
                    { "command": "open_recent_file", "args": {"index": 23 } },
                    { "command": "open_recent_file", "args": {"index": 24 } },
                    { "command": "open_recent_file", "args": {"index": 25 } },
                    { "command": "open_recent_file", "args": {"index": 26 } },
                    { "command": "open_recent_file", "args": {"index": 27 } },
                    { "command": "open_recent_file", "args": {"index": 28 } },
                    { "command": "open_recent_file", "args": {"index": 29 } },
                    { "command": "open_recent_file", "args": {"index": 30 } },
                    { "command": "open_recent_file", "args": {"index": 31 } },
                    { "command": "open_recent_file", "args": {"index": 32 } },
                    { "command": "open_recent_file", "args": {"index": 33 } },
                    { "command": "open_recent_file", "args": {"index": 34 } },
                    { "command": "open_recent_file", "args": {"index": 35 } },
                    { "command": "open_recent_file", "args": {"index": 36 } },
                    { "command": "open_recent_file", "args": {"index": 37 } },
                    { "command": "open_recent_file", "args": {"index": 38 } },
                    { "command": "open_recent_file", "args": {"index": 39 } },
                    { "command": "open_recent_file", "args": {"index": 40 } },
                    { "command": "open_recent_file", "args": {"index": 41 } },
                    { "command": "open_recent_file", "args": {"index": 42 } },
                    { "command": "open_recent_file", "args": {"index": 43 } },
                    { "command": "open_recent_file", "args": {"index": 44 } },
                    { "command": "open_recent_file", "args": {"index": 45 } },
                    { "command": "open_recent_file", "args": {"index": 46 } },
                    { "command": "open_recent_file", "args": {"index": 47 } },
                    { "command": "open_recent_file", "args": {"index": 48 } },
                    { "command": "open_recent_file", "args": {"index": 49 } },
                    { "command": "open_recent_file", "args": {"index": 50 } }
                ]
            }
        ]
    }
]

结果:

(出于安全考虑,需要模糊图像的某些部分)

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。(。表示当前目录)