I am trying to perform the following:
- open a gnome-terminal from keyboard shortcut, say Ctrl+Shift+E.
- 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).
- 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:
- I can bind a keyboard shortcut in the settings to
gnome-terminal: It opens a terminal as expected.
- 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.
- 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-terminalopens 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)$ && exitat the end of my .bashrc, a keyboard shortcut with the command
gnome-terminalopens 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.