Skip to content

Instantly share code, notes, and snippets.

@shovon
Last active June 8, 2018 12:25
Show Gist options
  • Save shovon/dce46a760eec5bb76dac to your computer and use it in GitHub Desktop.
Save shovon/dce46a760eec5bb76dac to your computer and use it in GitHub Desktop.
"subl" command in Linux

OS X's Sublime Text has this subl command, where running it from the terminal will summon Sublime Text, in the background. This means that closing the terminal window will not close Sublime Text.

In Linux, we can do that with the help of nohup. Assuming you have installed a sublime_text command that opens a new process associated with Sublime Text, then you can do

$ nohup sublime_text &

When you close your terminal window, Sublime Text will still remain open.

Now let's add the subl command to Linux, shall we? Create a "subl" file in /usr/bin, and in it, write out:

#!/bin/bash

nohup sublime_text $@ >/dev/null 2>&1 &

(The >/dev/null 2>&1 right before the final & instructs Bash to throw all console output (be it the regular output, or error output) to /dev/null, which, the OS simply ignores)

And then, make /usr/bin/subl executable:

$ chmod +x /usr/bin/subl

Then, run subl, and you should see Sublime Text show up. Close your terminal window, and watch Sublime Text remain open.

@sylbru
Copy link

sylbru commented Jun 8, 2018

Just for the information of people reading this now: Linux's Sublime Text has had the subl command as well for some time now. Maybe depending on the installation mode, I don't know.

It's interesting to compare this built-in subl with the solution proposed here. The /usr/bin/subl file contains the following:

#!/bin/sh
exec /opt/sublime_text/sublime_text "$@"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment