在终端中使用。subl

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

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


如果你将subl设置为从命令行调用,打开当前目录的正确命令是:

苏布尔 .

“OS X命令行”是一个关于如何确保一切都已设置好的链接。


我终于让这个在我的OSX盒子上工作了。我使用以下步骤让它工作:

Test subl from your ST installation: 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 . 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 ".bash_profile": 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' 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. 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. Create a symbolic link to Sublime Text: 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 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. 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.


这适用于我(我使用OS X Mavericks)

首先,创建一个符号链接:

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

现在你可以打开升华

subl "/a/path/to/the/directory/you/want/to/open"

对于MAC 10.8+:

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

工作。


我在Mac OSX Mavericks上使用oh-my-zsh,符号链接不适合我,所以我在.zshrc文件中添加了一个别名:

alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"

打开一个新终端,然后输入subl。


我想补充的是,如果你从Sublime Text 2升级,进入/usr/bin,先删除你的旧subl,然后再按照上面相同的指示。值得升级。


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

open -a "sublime text" [file]

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


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

步骤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 Text 2的OS X Mavericks中,以下内容对我来说是有效的。

sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin/subl

在查找器中找到文件并将其拖放到终端窗口中很方便,这样你就可以确保路径是正确的,我不是一个巨大的终端用户,所以这对我来说更舒服。然后您可以转到路径的开头并开始添加其他部分,例如简写UNIX命令。希望这能有所帮助


请注意不要写入/usr/bin,而是写入/usr/local/bin。 第一个是为应用程序写入二进制到系统中,最新的是为特定的用途,使我们自己的系统范围的二进制文件(这是我们在符号链接的情况下)。

此外,/usr/local/bin读取在/usr/bin之后,因此也是覆盖任何默认应用程序的好地方。

考虑到这一点,正确的符号链接应该是:

ln -s /Applications/Sublime\ Text。应用程序/内容/ SharedSupport / bin / subl /usr/local/bin/subl


假设:

您已经安装了Homebrew。 /usr/local/bin在$PATH中。 你在约塞米蒂或酋长岩。

MacOS Sierra 10.12.5已被David Rawson确认,MacOS Sierra 10.12.6已被Alexander K。

在Terminal中运行以下脚本创建特定的符号链接。

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

然后:

subl .

点击返回,它应该立即打开Sublime Text。


我在终端中只用一行就实现了这一点(使用Sublime 3):

alias subl='/usr/local/bin/sublime'

除非真的需要,否则不应该污染/usr/bin目录。 对于那些不受分发包管理器管理的二进制文件,我总是使用/usr/local/bin。为什么?因为如果包管理器更新了,它总是会替换/usr/bin中的文件。

我要做的是

sudo ln -s /Applications/Sublime\ Text。应用程序/内容/ SharedSupport / bin / subl /usr/local/bin/subl


你可以添加一个别名

alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'

然后你就可以打开文件夹了

subl <path>

我用的是mac,这对我来说很管用:

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

将它添加到你的.bashrc或.zshrc是一个简单的解决方案。

alias sublime="open -a /Applications/Sublime\ Text.app"

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


它工作!!!!MacOS Sierra 10.12.2

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

在终端subl找到它


任何人寻找打开一个文件与升华的mac终端

open 'path/file.txt' -a '/Applications/Sublime Text.app'

亲密的崇高。执行该命令。它会卸载它。你不会失去你的偏好。然后再运行一次。它将自动绑定subl。

brew install Caskroom/cask/sublime-text

你可以在Terminal中创建一个新的别名:

nano ~/.bash_profile

复制这一行并粘贴到编辑器中:

alias subl='open -a "Sublime Text"'

点击control + x,然后y,然后回车保存并关闭它。

关闭所有终端窗口并重新打开。

就是这样,你现在可以使用subl filename或subl。

更新zsh:

自macOS 10.15 Catalina开始,默认shell更改为zsh。

nano ~/.zshrc

其余步骤保持不变。


这是为了让它作为一个别名工作,而不是一个符号链接!

这将允许您在终端中运行额外的命令,而不会中断子会话。使用这里的许多符号链接答案(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.


试试这个。

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

我正在使用mac airbook打开你的终端并键入

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

然后键入简单的subl和文件名

 subl index.py

我使用的是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

总结一下实现目标的不同方法:

从终端打开崇高文本

open /Applications/Sublime\ Text.app/

使用sublime text打开当前路径下的特定文件(或提供需要打开的文件的路径)

open -a /Applications/Sublime\ Text.app/ myFileToOpen.txt

通过引入一个名为“sublime”的新别名并使用它,使您的命令变得简短 A. open bash_profile: 纳米~ / . bash_profile B.复制这一行以创建别名并保存并重启终端 alias sublime="open -a /Applications/ sublime \ Text.app" apple.txt将以sublime文本打开(必要时提供文件路径) 崇高apple.txt


下面的方法对我很有效

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

在默认路径下创建文件对我来说不能作为菜单。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的设置文档

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

工作很好。


从macOS Catalina(10.15版本)开始使用zsh。为了允许Sublime从命令行运行,在你的主目录中编辑.zshrc(不带参数的cd会让你到达那里),并添加以下行:

export PATH="$PATH:/Applications/Sublime Text.app/Contents/SharedSupport/bin"

使用subl [filename]从命令行运行Sublime Text


对于Sublime 4+,使用Bash甚至更简单:

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

遵循Sublime文档即可

Bash

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

ZSH

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

Linux

sudo ln -s /opt/sublime_text/sublime_text /usr/local/bin/subl

执行命令后,请务必关闭终端。

使用

要查看可用的标志,运行subl——help。