I am trying to perform the following:

  1. open a gnome-terminal from keyboard shortcut, say Ctrl+Shift+E.
  2. Run a command in the terminal. For concrenetess, the command is gio open $(fzf). The command is interactive and launches external program (such as evince).
  3. Once the external program is started, close the terminal without closing the external program.

The command I am interested in for step 2 above is gio open $(fzf): I select a file using the fuzzy finder fzf, and then the command gio open opens that file with the default program of gnome.

I can do the three steps above one by one:

  1. I can bind a keyboard shortcut in the settings to gnome-terminal: It opens a terminal as expected.
  2. Then I type in the newly opend terminal my command gio open $(fzf): If I select a pdf file from fzf, it opens evince with the selected file.
  3. I can type Ctrl+D to close the terminal. Doing this does not close evince. This is the intended behavior.

and doing these three steps manually works.

My goal is to automate the above. It should work as follows. As I type the keyboard shortcut Ctrl+Shit+E (or any other), a gnome-terminal should open, and the command gio open $(fzf) should be run. As soon as the interactive command is done (which opens an external program such as evince), the terminal should close automatically without closing evince.

What I have tried.

  • Adding a keyboard shortcut with the command gnome-terminal -- bash -c "gio open $(fzf)" does not work. Pressing the key combination does nothing.
  • If I add the command gio open $(fzf)$ at the end of my .bashrc, a keyboard shortcut with the command gnome-terminal opens the terminal and the command is run. As soon as I select a pdf file, evince is opened with the selected file (yeah!!!). But then, if I hit Ctrl+D, the terminal closes and so does evince (maybe because evince is a subprocess?).
  • If I add the command gio open $(fzf)$ && exit at the end of my .bashrc, a keyboard shortcut with the command gnome-terminal opens the terminal and the command is run, but as soon as I select a file, the terminal closes without opening evince (evince might have started and got closed immediately, I cannot tell).

Note that playing with .bashrc was mostly for testing purposes, I would like to avoid polluting my .bashrc.

  • Launch terminal from keyboard shortcut, what about ctrl+alt+t – Abdulla Nilam Oct 26 '17 at 18:01
  • The keyboard shortcut should, with only one keypress, launch terminal and run the interactive command. – jlewk Oct 27 '17 at 20:26

But then, if I hit Ctrl+D, the terminal closes and so does evince (maybe because evince is a subprocess?)

Yes, sure, it's subprocess and you should run this process as "detached". After that you can end main process (in your case - terminal).

Here is detailed answer how to run detached processes.


As another way you can use the next shortcut:

bash -c "some_command" > /dev/null &2>&1

In this case terminal window will not be raised at all and you don't need to add anything to your .bashrc file.

| improve this answer | |
  • Hi and thanks for your help. Actually, when I am in an already opened terminal, the command gio open $(fzf) opens an external program (such as evince), and if later I close the terminal with Ctrl+D, the external program is NOT closed. The external program is closed only in the situation where the command is run from .bashrc. – jlewk Oct 27 '17 at 20:40

The same thing was bugging me, so I'll answer this old question. I've found that xdg-open and gio open have trouble with this sort of script, and I've also noticed gnome-terminal has trouble with it. For example, xdg-open can open gedit to edit text files, but not evince to view pdfs. So I use the following script with xterm -e. Note that this will leave nohup.out files in your home directory, you can redirect stdout if that bothers you.



[ - n "$file" ] || exit 1


case $end in
  pdf | djvu | ps )
    exec nohup evince "$file"
  * )
    exec nohup xdg-open "$file"

| improve this answer | |

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.