Stupid Shell Trick

Launching GUI apps from the shell is often a pain. No longer!

I complained about Sublime Text 2 and how, as shipped, it didn't launch independently of the shell used to launch it.  I solved the problem with a bit of hackery tonight and it solves the problem for any GUI app (including the other editors I mentioned that shared ST2's problem).  This trick has been tested in both bash and zsh and is known to work.  It will probably work in any other Bourne shell-alike (dash, ksh, etc.) but I leave testing this to people who use these.  Similar tricks will probably work in csh and its offshoots with a bit of tweaking.

 

First, put this function somewhere in your shell startup:

 

1
2
3
launch() {
    ( $* &> /dev/null & )
}

 

Now for any GUI app that you want to launch from the shell without having your shell locked up, cluttered up with jobs or with stderr/stout trash, write aliases like these ones (for Sublime Text 2, Textadept and Emacs respectively):

 

1
2
3
alias st='launch sublime_text'
alias ta='launch textadept'
alias emacs='launch emacs'

 

Problem solved.

Filed under:
Bahman Movaqar
Bahman Movaqar says:
Jan 09, 2013 07:28 AM

Again there's no need for such an alias for Emacs. Run `emacs --daemon' and then use `emacsclient -c' to very quickly launch an Emacs window :-)

Michael T. Richter
Michael T. Richter says:
Jan 13, 2013 08:06 PM

Yes, I can see how running the "emacs" once with a long command line option and then an even *longer* command name ("emacsclient") with a different command line option would be far easier and smarter than just typing "launch emacs" or even just "emacs"….

Bahman Movaqar
Bahman Movaqar says:
Jan 13, 2013 10:50 PM

I have `alias vi='emacsclient -t'` in `.bashrc` :-D