Disable CTRL-D from closing my window with the terminator terminal emulator)

I am often logged in several SSH sessions at once. To logout from several sessions, I press CTRL+d, until I am back on my local machine.

However, I occasionally press it once too many, and my terminal exits.

Is there a way to make CTRL+d unable to close my terminal ?

I am using terminator as my terminal emulator.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can also disable eof generally in bash:

set -o ignoreeof

Method 2

You can use the IGNOREEOF environment variable in bash. So export IGNOREEOF=42 and you’ll have to press Ctrl+D forty-two times before it actually quits your shell.

POSIX set has an -o ignoreeof setting too.

Method 3

The Ctrl-D EOF character is being interpreted by the shell, rather than the terminal emulator specifically. Other answers have covered bash settings, although other shells are different.

For C-shells (e.g. tcsh) you can add it to your tcshrc file:

# Prevent accidental logouts completely
set ignoreeof
# Just prevent the first two, and allow the third
set ignoreeof=3

For fish shell, the Ctrl-D behaviour is controlled by the keybinding. The default setting is delete-or-exit, so you can set the keybinding for cd to delete-char to only support delete.

More details are in the Fish Github issue (e.g. in versions before 3.0 you need to add the bind to a function called fish_user_key_bindings, after 3.0 you can put it into ~/.config/fish/config.fish) but in summary:

bind cd delete-char  # Don't exit on accidental Ctrl-D
bind cdcdcd delete-or-exit  # Exit on the third one


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x