I am using Ubuntu 16.04 and gnome-terminal 3.18.3.

I can't seem to find an option to get a warning before (accidentally) closing the terminal. It seems like that there used to be an option to change it in gconf-editor (apps -> Gnome-Terminal) but it is not there anymore.

I see a few similar but unanswered questions for other terminal on this as well (e.g. Terminal not prompting before closing and Make terminator ask for permission before closing if something is being executed)

  • The two links shared are the same question – M. Becerra Mar 20 '17 at 18:33
  • They don't share the same question, the first one regards to LXTerminal and asks for a prompt regardless of the state, the second one regards to Terminator and asks for a prompt in the state if a a foreground is running. – cmks Mar 20 '17 at 21:22

Short answer: gnome-terminal only prompts you if a foreground process is active and the configurable option confirm-close is true.

The long answer is:

As you can see in source code, gnome-terminal checks vor TERMINAL_SETTING_CONFIRM_CLOSE_KEY when it receives a window close request.

Here you will see that it maps to confirm-close.

You may get or set this setting using

gsettings get org.gnome.Terminal.Legacy.Settings confirm-close
gsettings set org.gnome.Terminal.Legacy.Settings confirm-close true

The source of the function that decides if a confirmation is needed is here.

gnome-terminal only asks for a confirmation if confirm-close is true and if a foreground process is active in at least one tab. So if you want to always be asked before closing a gnome-terminal window you have create one tab and start a foreground process in it, i. e.

ping -i 10

Furthermore you have to activate tabs:

menu -> terminal -> settings -> open new terminal in: tabs

You may create a gnome-terminal profile which starts such a process automaticly. So you can configure gnome-terminal to start that profile on startup or you may easy start it yourself selecting

file -> new terminal -> your profile

from the menu.

  • works for gnome-terminal version 3.26.2 – Trismegistos Jan 22 '18 at 11:33

In my case, I wanted to have a profile that ran nvim. Since gnome-terminal wouldn't know if the buffer had unsaved changes, I wanted it to always prompt.

To that end, instead of making the profile command nvim, I made it /bin/sh -i -c nvim. The -i, making the shell interactive, makes gnome-terminal think that nvim is a foreground job that has yet to exit. Thus it will always prompt.

Perhaps you can use something like that.

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.