bash - 将前缀 key 发送到 tmux session

标签 bash shell terminal tmux

所以我使用这个 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/

相关文章:

macos - 在Mac OS(OS X)中登录时启动Shell脚本

xcode - 打开 Xcode 项目并从终端设置事件文件

php - 文件对于直接从 php-cli 运行的 php 代码是可读的,对于通过 bash 脚本中的 php-cli 运行的 php 代码是不可读的

c - 如何使用 C 语言获取终端上显示的书面字符串并将其保存在文本文件中?

mysql - 无法通过socket '/tmp/mysql.sock'连接到本地MySQL服务器(2)

linux - 如何处理 wget 下载链接中的特殊字符?

linux - 如何从下载的网页中提取信息?

linux - Bash 脚本 : Read a file and process it

bash - Bash 中的定时器事件

linux - bash 脚本 : calculate sum size of files