How to Launch Gedit from Terminal and Detach It

background-processbashgedit

To open a file to edit in gedit I run gedit sample.py &. But with Sublime Text it is simply subl sample.py. This opens the file to edit and it doesn't run in the background (in my shell).

How would I do that with gedit?

I tried exec /usr/bin/gedit "$@" (copied from /usr/bin/subl) but it works like gedit &.

Or alias ged="gedit $file &" should do. What can I substitute $file in the alias?

Best Answer

You could use this function:

gedit() { /usr/bin/gedit $@ & disown ;}

It:

  • Makes a function which can be called with gedit
  • Launches gedit (using the full path /usr/bin/gedit), passing all the arguments/files given to it using $@
  • & disown sends it to background and disown detaches it from the terminal/shell.
Related Question