I frequently use Ctrl-D to exit interactive python sessions but sometimes I would accidentally hit it when the python session was not on. This will result in sending an EOF to the shell and subsequently closing it (without asking for confirmation). I have come to two solution from googling around:
set -o ignoreeof
export IGNOREEOF=10
The first option worked perfectly in my zsh shell and bash shell.
However, the second option seems to only work in bash. When I'm in zsh,
whatever number I set for IGNOREEOF
, it sends EOF just like it was not set.
Can someone help with why ZSH behave this way or is it just the result of some peculiar env setup in my zsh shell?
Best Answer
Zsh does not use the
IGNOREEOF
parameter like Bash does. Instead, it is an option that you must set via thesetopt
builtin. Fromzshoptions(1)
:-- The second paragraph is important if you wish to emulate Bash's IGNOREEOF; see below
You can enable this option by adding the following to your shell configuration:
Emulating Bash (Optional)
If you would like to emulate the Bash behavior of being able to specify the number of Ctrl+D sequences before exiting the shell, then you can add the following ZLE widget definition* to your configuration:
Then, add the widget to ZLE and create a keybind for it:
You will still need to set the
ignore_eof
option however, otherwise Ctrl+D will ignore ZLE and immediately exit the shell regardless of this widget. Refer to the second paragraph of the man page snippet at the beginning of the answer.* - Credit for this widget goes to its original author, Christoph Lange, and Bart Schaefer for his corrections