找到正确的 tmux 发送键到自定义套接字和会话语法

找到正确的 tmux 发送键到自定义套接字和会话语法

我试图正确获取发送键参数的语法,并尝试了一些我试图从手册页中拼凑起来的变体,但我一定是误解了一些东西。

我以以下方式初始化 tmux 并希望按照下面所示对其进行操作。

sudo -H -u username1 -g usergroup1 bash -c '/usr/bin/tmux -S /home/shares/tmux_sessions/sock_file new -d -s "sess-tv0-i" mycommand -arg1 -arg2'
sudo -H -u username1 -g usergroup1 bash -c '/usr/bin/tmux -S /home/shares/tmux_sessions/sock_file new -d -s "sess-tv1-i" mycommand -arg1 -arg2'
sudo -H -u username1 -g usergroup1 bash -c '/usr/bin/tmux -S /home/shares/tmux_sessions/sock_file new -d -s "sess-tv2-i" mycommand -arg1 -arg2'

我尝试将密钥发送到单个会话,但是下面的命令似乎将命令发送到所有会话,这是不希望的,我希望一次只将密钥发送到 1 个会话。

tmux -S /home/shares/tmux_sessions/sock_file send-keys C-c -t sess-tv0-i

使用上述命令不会出现任何错误,但是如上所述,它确实将该密钥字符串发送到该套接字中的多个会话。

我也尝试过下面的操作,但失败了。

tmux -S /home/shares/tmux_sessions/sock_file target-session -t sess-tv0-i send-keys C-c
unknown command: target-session

tmux target-session -t sess-tv0-i send-keys C-c
error connecting to /tmp/tmux-0/default (No such file or directory)

tmux -S /home/shares/tmux_sessions/sock_file -t sess-tv0-i send-keys C-c
tmux: unknown option -- t
usage: tmux [-2CluvV] [-c shell-command] [-f file] [-L socket-name]
            [-S socket-path] [command [flags]]

谢谢您的任何建议或为我指明正确的方向。

答案1

明显的错误是使用

tmux -S /home/shares/tmux_sessions/sock_file send-keys C-c -t sess-tv0-i

它将把 Cc 或 Control+c 键发送到该 sock 文件中的所有会话,而不是使用

tmux -S /home/shares/tmux_sessions/sock_file send-keys -t sess-tv0-i C-c

这允许正确评估 -t 标志。

相关内容