将前缀键发送到 tmux 会话
Send prefix key to tmux session
所以我使用这个 tmux 插件来记录整个 tmux 历史记录。 https://github.com/tmux-plugins/tmux-logging
该插件使用键绑定 C-b
+ P
来启动和停止日志记录会话。基本上,prefix
+ P
.
我正在以编程方式尝试停止和启动日志记录会话,以便为每一天创建一个新的输出文件。为此,我想设置一个 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 会话时,我看到的是打印在屏幕上的内容。
^BP^BP
所以 C-b
不是被视为 prefix
,而是被视为普通组合键。我也尝试过使用以下方法,但结果仍然相同。
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
是此脚本所在的目录。
因此,在您的计算机上找到该脚本,然后将您的发送密钥更改为
tmux send-keys -t 0:0 '$SCRIPT_DIR/scripts/toggle_logging.sh' Enter
所以我使用这个 tmux 插件来记录整个 tmux 历史记录。 https://github.com/tmux-plugins/tmux-logging
该插件使用键绑定 C-b
+ P
来启动和停止日志记录会话。基本上,prefix
+ P
.
我正在以编程方式尝试停止和启动日志记录会话,以便为每一天创建一个新的输出文件。为此,我想设置一个 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 会话时,我看到的是打印在屏幕上的内容。
^BP^BP
所以 C-b
不是被视为 prefix
,而是被视为普通组合键。我也尝试过使用以下方法,但结果仍然相同。
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
是此脚本所在的目录。
因此,在您的计算机上找到该脚本,然后将您的发送密钥更改为
tmux send-keys -t 0:0 '$SCRIPT_DIR/scripts/toggle_logging.sh' Enter