TransWikia.com

Make gnome-terminal request user confirmation before close

Ask Ubuntu Asked by ynn on October 31, 2021

When you open gnome-terminal without any options and execute a blocking command (e.g. python3, vim or cat) and then try to close the window by the close button (i.e. x button in the title bar) or some keyboard shortcut, a confirmation window is displayed:

enter image description here

However, when you open gnome-terminal with an executed command specified, that is, in the form of gnome-terminal -- python3, the confirmation window is no longer displayed and the window is closed right after you (accidentally) click the close button.

Is it possible to show the confirmation window even when you use the form gnome-terminal -- <command>? If that’s impossible, is there any workarounds?


Environments:

$ gnome-terminal --version
# GNOME Terminal 3.36.2 using VTE 0.60.3 +BIDI +GNUTLS +ICU +SYSTEMD

What I’ve Tried:

  • Equipping the executed command with signal handlers for all the supported signals didn’t work; the window was still closed without confirmation although the process survived the closure while catching SIGHUP (three times), SIGCONT (once) and SIGWINCH (once). I had additionally to execute kill -SIGKILL <process id> to kill the process.

  • I found one exception. When you execute gnome-terminal -- bash, the confirmation is displayed (though this is by default the same as gnome-terminal).

One Answer

GNOME Terminal checks if there is foreground process started by shell (see terminal_screen_has_foreground_process function)

You can use sh to create new process and gnome-terminal to ask before exit this way:

gnome-terminal -- sh -i -c python3

Update: The same effect may be achieved with bash using custom script:

gnome-terminal -- bash -i my_script.sh

and the content of my_script.sh is just

python3

Answered by Mateusz on October 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP