[懶人工具箱] 在mac命令行中快速開啟sublime
場景說明:
相信大家在使用mac開啟或編輯檔案時,都有遇過下面類似的問題:
- 使用內建的文字編輯器字體顏色清一色,找不到我要的內容。
- 檔案內容太大了,使用IDE開啟太慢了。
- 想要編輯檔案內容,但是系統沒有安裝支援的程式。
…等。
而基於上面場景我習慣用sublime去開啟檔案再做後續的處理,雖然mac本身也是支持拖曳/選擇指定程式去打開檔案解決問題。
但相信很多的後端工程師跟我一樣,比起圖形化介面我們更常在命令行下處理我們的工作。
而sublime本身也支援在命令列裡面呼叫程式,只是檔案路徑太落落長了。但好消息是可以透過下面的方法去設定快捷開啟。
設定方式:
其他的編輯器/應用程式也可以嘗試修改,下面以sublime為例
- 打開你的command_line工具。
- 使用軟連結
ln -s source_app /usr/local/bin/cmd_name
- source_app: 要啟動的app,使用絕對路徑,例:
/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
- cmd_name: 自訂的命令名稱,建議以自己好記為主。例:subl
3. 使用sublime開啟指定的檔案,例如file01.txt
原始內容長這樣;
使用設定的快速鍵subl開啟檔案
完成,後面就可以省去把檔案拖來拖去的時間直接透過命令行簡化你的工作流啦。
關於其他指令以及進階的用法可參考sublime官方說明
Usage: subl [arguments] [files] edit the given files
or: subl [arguments] [directories] open the given directories
or: subl [arguments] - edit stdin
Arguments:
--project <project>: Load the given project
--command <command>: Run the given command
-n or --new-window: Open a new window
-a or --add: Add folders to the current window
-w or --wait: Wait for the files to be closed before returning
-b or --background: Don't activate the application
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help (this message) and exit
-v or --version: Show version and exit
--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).
Filenames may be given a :line or :line:column suffix to open at a specific
location.