Search code examples
linuxterminalwindow-managers

Launch Linux graphical application from a terminal with "exec" command behaviour


I am using i3-wm on Linux, and I am trying to imitate the behaviour of a program launcher. I already know about the "exec" command, which seems to work as expected for non-graphical commands.

For example, if I type in a terminal:

exec sudo ls -aR

I will get a list of all folders and files of the current directory. When the command exits, the terminal disappears.

But if I type instead in a terminal:

exec chromium-browser

I will end up with two windows: one being chromium; the other one being the terminal that launched chromium, now used by chromium to print debug info.

How can I start i.e. chromium-browser from a terminal and keep it alive while hiding or killing the terminal that launched it?


Solution

  • I found the answer. I had to start a graphical application in background ("&") and then "disown" it, like that:

    chromium-browser & disown

    In my case, I have to kill the terminal after doing so:

    chromium-browser & disown && exit

    Note the use of "&&" instead of ";". If disowning no job, then not exiting.

    By the way, in my case, I found that making an alias x having disown && exit as value could come in handy. If I want to start a graphical application from the terminal, then this is how I do it:

    chromium-browser &x

    I just thought mentioning this could maybe help someone else.