在macOS中從終端打開Sublime Text

本文翻譯自:Open Sublime Text from Terminal in macOS

In Terminal when I use .subl 在終端中,當我使用.subl

It returns -bash: .subl: command not found 它返回-bash: .subl: command not found

Anyone know how to open Sublime Text 3 from the command line in macOS? 有人知道如何從macOS的命令行中打開Sublime Text 3嗎?


#1樓

參考:https://stackoom.com/question/15yFZ/在macOS中從終端打開Sublime-Text


#2樓

if you have subl set up to be called from the command line, the proper command to open the current directory is: 如果已設置要從命令行調用的subl,則打開當前目錄的正確命令是:

subl .

" OS X Command Line " is a link on how to make sure everything is set up. OS X命令行 ”是有關如何確保所有設置均已設置的鏈接。


#3樓

I finally got this to work on my OSX box. 我終於可以在OSX盒子上使用它了。 I used these steps to get it to work: 我使用以下步驟使其正常工作:

  1. Test subl from your ST installation: 從ST安裝中測試subl

    First, navigate to a small folder in Terminal that you want ST to open and enter the following command: 首先,在終端中導航到要ST打開的小文件夾,然後輸入以下命令:

     /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. 注意:您可能需要在上面的命令Sublime\\ Text.app替換爲Sublime\\ Text\\ 3.appSublime\\ Text\\ 2.app具體取決於應用程序在Applications目錄中的存儲位置。 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. 如果您沒有在打開當前工作目錄時看到Sublime Text,則接下來的步驟將不起作用。 If nothing happens or you get an error from Terminal it will be because it couldn't find the Sublime Text application. 如果什麼也沒發生,或者您從Terminal收到錯誤消息,那是因爲它找不到Sublime Text應用程序。 This would mean that you would have to check what you've typed (spelling, etc.) OR that Sublime Text isn't installed! 這意味着您將必須檢查您鍵入的內容(拼寫等),或者未安裝Sublime Text!

  2. Check ".bash_profile": 檢查“ .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 . 現在是時候在PATH文件夾BUT中創建符號鏈接了,在此之前,讓我們使用nano ~/.bash_profile檢查您的配置文件。 These are the following lines that pertain to having subl work on the command line for Sublime Text: 這些是與在Sublime Text的命令行上使subl工作有關的以下行:

     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. 第一行設置您希望終端在計算機上查找二進制文件的位置,我將把符號鏈接存儲在/usr/local/bin目錄中-我猜您可以將其存儲在通知終端的任何位置在哪裏尋找二進制文件。

    The second line is OPTIONAL and just sets Sublime Text as the default editor. 第二行是OPTIONAL,僅將Sublime Text設置爲默認編輯器。 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 標誌-w已添加,您可以通過轉到Sublime Text文檔: ST3 sublST2 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. 如果在採購文件後看到任何錯誤,請先進行修復,然後再進行最後一步。

  3. Create a symbolic link to Sublime Text: 創建一個符號鏈接到Sublime Text:

    Now in your chosen path (I used /usr/local/bin ) you now enter the following command: 現在在您選擇的路徑(我使用/usr/local/bin )中,輸入以下命令:

     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. /Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl與上述步驟1中輸入並驗證爲可以使用的位置完全相同。 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. /usr/local/bin/subl是您希望符號鏈接位於的位置-必須是上述STEP 2中的PATH位置之一。

    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 . 現在,當您導航到要在Sublime Text中打開的文件夾或文件時,現在只需輸入subl然後輸入文件名或即可. to open the current working directory. 打開當前工作目錄。


#4樓

This worked for me (I'm using OS X Mavericks) 這對我有用(我正在使用OS X Mavericks)

First, create a symbolic link: 首先,創建一個符號鏈接:

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

Now you can open sublime with 現在您可以打開

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

#5樓

For MAC 10.8+: 對於MAC 10.8+:

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

worked. 工作了。


#6樓

I'm using oh-my-zsh on Mac OSX Mavericks and the symbol link didn't work for me, so I added an alias in my .zshrc file instead: 我在Mac OSX Mavericks上使用oh-my-zsh,符號鏈接對我不起作用,因此我在.zshrc文件中添加了一個別名:

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

Open a new terminal and you should be good to go, and type subl . 打開一個新的終端,您應該subl順利,然後輸入subl

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章