tmux-background-tasks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTmux Background Tasks
Tmux 后台任务
If tmux is not installed, stop and ask the user to install it before proceeding.
如果未安装tmux,请暂停操作并要求用户先安装tmux,然后再继续。
Overview
概述
Use tmux to run and manage long-lived commands in the background. Do not keep these tasks alive with the default process tool; always launch them in tmux so they survive across commands and can be reattached.
使用tmux在后台运行和管理长期运行的命令。不要使用默认进程工具保持这些任务运行;始终在tmux中启动它们,这样它们可以在多个命令执行期间持续运行,并且可以重新连接。
Workflow
工作流程
-
Verify tmux is installed If tmux is missing, stop and ask the user to install it (e.g.,on macOS). Do not proceed until tmux is available.
brew install tmux -
Pick a stable session name Use a predictable, unique name like(e.g.,
<repo>-<task>,myapp-api).myapp-expo -
Start or reuse the session Check for an existing session before starting a new one.
-
Provide attach/detach guidance Tell the user how to attach to the session if they want to view logs or interact.
-
Stop or restart when requested Terminate the session cleanly when the user asks to stop the task.
-
验证tmux已安装 如果缺少tmux,请暂停操作并要求用户安装(例如,在macOS上使用)。在tmux可用之前不要继续。
brew install tmux -
选择一个稳定的会话名称 使用可预测的唯一名称,例如(如
<repo>-<task>、myapp-api)。myapp-expo -
启动或复用会话 在启动新会话之前检查是否存在现有会话。
-
提供连接/断开连接的指导 告知用户如果想要查看日志或进行交互,如何连接到会话。
-
根据请求停止或重启 当用户要求停止任务时,干净地终止会话。
Command Patterns
命令模式
Check tmux:
command -v tmuxtmux -V
Create a new detached session running a command:
tmux new-session -d -s <name> -- <command>- If you need a login shell or env:
tmux new-session -d -s <name> -- bash -lc '<command>'
Reuse or attach:
tmux has-session -t <name>tmux attach -t <name>tmux ls
Send a stop signal or kill:
tmux send-keys -t <name> C-ctmux kill-session -t <name>
Peek at recent output (non-interactive):
tmux capture-pane -pt <name> -S -200
检查tmux:
command -v tmuxtmux -V
创建一个运行命令的新分离会话:
tmux new-session -d -s <name> -- <command>- 如果需要登录shell或环境:
tmux new-session -d -s <name> -- bash -lc '<command>'
复用或连接:
tmux has-session -t <name>tmux attach -t <name>tmux ls
发送停止信号或终止会话:
tmux send-keys -t <name> C-ctmux kill-session -t <name>
查看最近输出(非交互式):
tmux capture-pane -pt <name> -S -200
Notes
注意事项
- Prefer tmux for servers, watchers, workers, and dev tools that should remain running while other commands execute.
- Avoid creating duplicate sessions. If succeeds, reuse it or attach.
tmux has-session -t <name>
- 对于服务器、监视器、工作进程以及需要在执行其他命令时保持运行的开发工具,优先使用tmux。
- 避免创建重复会话。如果 执行成功,请复用该会话或连接到它。
tmux has-session -t <name>