我在我的服务器上使用 tmux,最近我发现 ctrl-d 会退出 tmux 并丢失所有会话信息,我的目的是简单地结束 ssh 会话,但没有注意到我仍然在 tmux 中,直到为时已晚。
我知道将来使用 ctrl-d 时应该小心,但我想知道是否有办法防止 tmux 在意外按下 ctrl-d 时退出?诸如提示、确认或分离之类的解决方案就可以了。
che*_*ner 43
准确地说,Ctrld不是 exit tmux,而是一个 shell。如果该 shell 正在tmux会话中最后一个窗口的唯一窗格中运行,则会话结束并且tmux客户端退出。
为了防止Ctrld退出shell,你可以设置IGNOREEOFshell变量,或者设置ignoreeofshell选项。将以下内容之一放入您的.bashrc文件中:
IGNOREEOF=10 # Shell only exists after the 10th consecutive Ctrl-d
set -o ignoreeof # Same as setting IGNOREEOF=10
Run Code Online (Sandbox Code Playgroud)
小智 14
IGNOREEOF对我不起作用,所以我只是将Ctrl+绑定D到detach.tmux.conf:
bind-key -n C-d detach
这-n意味着不需要先前的转义序列,例如 tmux 前缀。
除了chepner 的回答,您还可以通过设置eof为undefwith来完全阻止终端发送 EOF stty:
stty eof undef
Run Code Online (Sandbox Code Playgroud)
重置:
stty eof '^d'
Run Code Online (Sandbox Code Playgroud)