I am using fish shell. When I type Ctrl-D, it sends a EOF to my terminal and then terminal closes.
I want to make it such that ctrl-D does not close my iterm2.
I saw that people have set up IGNOREEOF in bash shell like this: https://unix.stackexchange.com/questions/27588/how-can-i-keep-controld-from-disconnecting-my-session
However, I don't think this variable exists in fish. Does anybody know how I can force iterm2(with default fish shell) to not close on ctrl-D?
This is the default key binding for control-D:
bind \cd delete-or-exit
you can find this by just running bind
.
(delete-or-exit
is just a function, which you can read with functions delete-or-exit
.)
So it's exiting because that's what the default behavior is. You can make control-D do something else. For example, maybe it should delete the character under the cursor:
bind \cd delete-char
If you want to make this permanent, add it to your fish_user_key_bindings
function:
funced fish_user_key_bindings
which starts editingbind \cd delete-char
within the functionfuncsave fish_user_key_bindings
to save itAfter reading this question and answer I updated my delete-or-exit function to ask for confirmation rather than completely deactivate it:
cd ~/.config/fish/functions/
cp /usr/share/fish/functions/delete-or-exit.fish .
Then edit/replace:
function delete-or-exit
set -l cmd (commandline)
switch "$cmd"
case ''
read --nchars 1 --local -P 'Do you want to exit? [y/N] ' confirm
switch $confirm
case Y y
exit 0
case '' N n
echo -n (fish_prompt)
end
case '*'
commandline -f delete-char
end
end
It has a minor issue in that it displays the prompt twice when you finish, but it seems better than no times if you don't print it (see N case above). Perhaps someone has a solution to that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With