![Tmux set-hook 会话附加不适用于选择树模式](https://linux22.com/image/226617/Tmux%20set-hook%20%E4%BC%9A%E8%AF%9D%E9%99%84%E5%8A%A0%E4%B8%8D%E9%80%82%E7%94%A8%E4%BA%8E%E9%80%89%E6%8B%A9%E6%A0%91%E6%A8%A1%E5%BC%8F.png)
我已经坐上了钩子.tmux.conf
。假设它应该在附加 tmux 会话后重新连接最后一个 SSH 会话。问题是它仅在使用附加会话时才有效tmux a -t session_name
。从选择树模式附加会话时,不会调用脚本。
set-hook -g session-attached 'run-shell "/opt/scripts/tmux_ssh_reconnext.sh"'
脚本:
#!/bin/bash
# Check if inside a TMUX session
if [ -n "$TMUX" ]; then
# Check if SSH connection exists
if [[ $(hostname) != "my_tmux_server" ]]; then
echo "SSH connection already established."
else
# Reconnect last SSH session
tmux send-keys -t 0 !ssh Enter
echo "SSH session reconnected inside TMUX."
fi
else
echo "Not inside a TMUX session."
fi