7

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?

  • How did you install sublime? – Wilf Jul 11 '15 at 10:17
  • @Wilf using apt-get add-apt-repository ppa:webupd8team/sublime-text-3 apt-get install sublime-text-installer – Sand1512 Jul 11 '15 at 10:19
  • Aliases don't take parameters, apart from that your alias doesn't have a closing double quote (or is that a typo) – Anthon Jul 11 '15 at 10:26
  • that was a typo.. – Sand1512 Jul 11 '15 at 10:29
  • 1
    I open lot of files at times. Shell gets messy and I don't want to type & or sometimes I forget to do that. And reaching shift+7 takes some time you know :-) – Sand1512 Jul 11 '15 at 16:40
4

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.
  • It works, great – Sand1512 Jul 11 '15 at 10:32
  • ok :) you can add it to ~/.bashrc, ~/.bash_aliases or something if you want it to load into bash when it starts. Sorry I don't know how sublime text launches to the background as it looks like it is compiled, and as it isn't open source you can't guess from the source code. – Wilf Jul 11 '15 at 10:34
  • yes added to .bashrc did that in first place :) – Sand1512 Jul 11 '15 at 10:41
2

If you're on a recent GNOME 3 setup you could also use gapplication1:

gapplication launch org.gnome.gedit sample.py

to launch gedit just like you'd launch it from the dash (detached from terminal).
Sure, you can always define an alias:

alias ged='gapplication launch org.gnome.gedit'

or a function:

ged () { gapplication launch org.gnome.gedit "$@"; }

This only works for D-Bus activatable applications (run gapplication list-apps to get a list of apps).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.