键入 Ctrl-D (EOF) 时如何防止 iterm2 关闭
How to prevent iterm2 from closing when typing Ctrl-D (EOF)
我正在使用鱼shell。当我键入 Ctrl-D 时,它会向我的终端发送 EOF,然后终端关闭。
我想让 ctrl-D 不会关闭我的 iterm2。
我看到人们在 bash shell 中设置了 IGNOREEOF 是这样的:https://unix.stackexchange.com/questions/27588/how-can-i-keep-controld-from-disconnecting-my-session
但是,我认为鱼中不存在这个变量。有谁知道我如何强制 iterm2(默认 fish shell)在 ctrl-D 上不关闭?
这是 control-D 的默认键绑定:
bind \cd delete-or-exit
你可以通过 运行 bind
.
找到这个
(delete-or-exit
只是一个函数,你可以用functions delete-or-exit
来读取它。)
所以它正在退出,因为这是默认行为。您可以让 control-D 做其他事情。例如,也许它应该删除光标下的字符:
bind \cd delete-char
如果你想让它永久化,请将它添加到你的 fish_user_key_bindings
函数中:
- 运行
funced fish_user_key_bindings
开始编辑
- 将
bind \cd delete-char
放入函数
- 点击return创建函数
- 运行
funcsave fish_user_key_bindings
保存
阅读这个问题和答案后,我更新了删除或退出功能以请求确认而不是完全停用它:
cd ~/.config/fish/functions/
cp /usr/share/fish/functions/delete-or-exit.fish .
然后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
它有一个小问题,当你完成时它会显示两次提示,但如果你不打印它似乎总比没有好(见上面的 N 个案例)。也许有人对此有解决方案。
除了向 Ctrl+d
分配不同的操作之外,您还可以通过 bind --erase --preset \cd
解除绑定。所有步骤:
- 运行
funced fish_user_key_bindings
开始编辑
- 将
bind --erase --preset \cd
放入函数
- 点击return创建函数
- 运行
funcsave fish_user_key_bindings
保存
我正在使用鱼shell。当我键入 Ctrl-D 时,它会向我的终端发送 EOF,然后终端关闭。
我想让 ctrl-D 不会关闭我的 iterm2。
我看到人们在 bash shell 中设置了 IGNOREEOF 是这样的:https://unix.stackexchange.com/questions/27588/how-can-i-keep-controld-from-disconnecting-my-session
但是,我认为鱼中不存在这个变量。有谁知道我如何强制 iterm2(默认 fish shell)在 ctrl-D 上不关闭?
这是 control-D 的默认键绑定:
bind \cd delete-or-exit
你可以通过 运行 bind
.
(delete-or-exit
只是一个函数,你可以用functions delete-or-exit
来读取它。)
所以它正在退出,因为这是默认行为。您可以让 control-D 做其他事情。例如,也许它应该删除光标下的字符:
bind \cd delete-char
如果你想让它永久化,请将它添加到你的 fish_user_key_bindings
函数中:
- 运行
funced fish_user_key_bindings
开始编辑 - 将
bind \cd delete-char
放入函数 - 点击return创建函数
- 运行
funcsave fish_user_key_bindings
保存
阅读这个问题和答案后,我更新了删除或退出功能以请求确认而不是完全停用它:
cd ~/.config/fish/functions/
cp /usr/share/fish/functions/delete-or-exit.fish .
然后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
它有一个小问题,当你完成时它会显示两次提示,但如果你不打印它似乎总比没有好(见上面的 N 个案例)。也许有人对此有解决方案。
除了向 Ctrl+d
分配不同的操作之外,您还可以通过 bind --erase --preset \cd
解除绑定。所有步骤:
- 运行
funced fish_user_key_bindings
开始编辑 - 将
bind --erase --preset \cd
放入函数 - 点击return创建函数
- 运行
funcsave fish_user_key_bindings
保存