所以我使用这个 tmux 插件来记录整个 tmux 历史记录。 https://github.com/tmux-plugins/tmux-logging
该插件使用键绑定(bind) C-b
+ P
来启动和停止日志记录 session 。基本上,前缀
+ P
。
我正在以编程方式尝试停止和启动日志记录 session ,以便每天创建一个新的输出文件。为此,我想设置一个 crontab 来运行一个简单的脚本。脚本内容如下。
tmux send-keys -t 0:0 C-b P # stops the logging session
tmux send-keys -t 0:0 C-b P # restarts the logging session
但是当我附加到 tmux session 时,我看到的是打印在屏幕上的内容。
^BP^BP
因此,C-b
不再被视为前缀
,而是被视为普通的组合键。我也尝试过使用以下方法,但结果仍然相同。
tmux send-prefix -t 0:0 # prints ^B on the session window
tmux send-keys -t 0:0 P
解决这个问题的方法是什么?
最佳答案
根据the maintainer of tmux , "You can't trigger tmux key bindings with send-keys. You could just run the commands the key is bound to instead." .
对于您的具体情况,我看到in logging.tmux :
tmux bind-key "$logging_key" run-shell "$CURRENT_DIR/scripts/toggle_logging.sh"
tmux bind-key "$pane_screen_capture_key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh"
tmux bind-key "$save_complete_history_key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh"
tmux bind-key "$clear_history_key" run-shell "$CURRENT_DIR/scripts/clear_history.sh"
其中 $CURRENT_DIR
是此脚本所在的目录。
因此,在您的计算机上找到该脚本,然后将您的发送 key 更改为
tmux send-keys -t 0:0 '$SCRIPT_DIR/scripts/toggle_logging.sh' Enter
关于bash - 将前缀 key 发送到 tmux session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64995878/