tmux
tmux
Terminal multiplexer for background processes, output capture, and session management. Every process runs in a named session you can inspect later.
Running Background Processes
Start a command in a named detached session:
tmux new-session -d -s myserver 'python -m http.server 8080'
tmux new-session -d -s build -c /path/to/project 'make build'
Keep a session alive after the command completes:
tmux new-session -d -s task 'command; exec bash'
Only create if it doesn't exist:
tmux has -t myserver || tmux new-session -d -s myserver 'command'
Capturing Output
Get the output from a running session:
tmux capture-pane -t mysession -p # Visible output only
tmux capture-pane -t mysession -p -S - # Full scrollback history
tmux capture-pane -t mysession -p -S -100 # Last 100 lines
tmux capture-pane -t mysession -p > file.txt # Save to file
Sending Input
Send keystrokes to a session:
tmux send-keys -t mysession 'echo hello' Enter # Type and press Enter
tmux send-keys -t mysession C-c # Send Ctrl+C
Waiting for Completion
Signal when a job finishes, then wait for it:
tmux new-session -d -s job 'command; tmux wait-for -S job-done'
tmux wait-for job-done
Session Management
tmux ls # List all sessions
tmux kill-session -t myserver # Kill specific session
tmux kill-server # Kill all sessions
Common Patterns
Development servers:
tmux new-session -d -s backend 'bun run backend'
tmux new-session -d -s frontend 'bun run frontend'
Run and capture output in a script:
tmux new-session -d -s job 'command'
sleep 0.5
output=$(tmux capture-pane -t job -p)
echo "$output"
Tips
- Use
-c /pathto set working directory when creating a session - Use
exec bashto keep sessions alive after commands finish - Use
-S -withcapture-paneto get full scrollback history
More from knoopx/pi
podman
Manages containers, builds images, configures pods and networks with Podman. Use when running containers, creating Containerfiles, grouping services in pods, or managing container resources.
123jujutsu
Manages version control with Jujutsu (jj), including rebasing, conflict resolution, and Git interop. Use when tracking changes, navigating history, squashing/splitting commits, or pushing to Git remotes.
117nix-flakes
Creates reproducible builds, manages flake inputs, defines devShells, and builds packages with flake.nix. Use when initializing Nix projects, locking dependencies, or running nix build/develop commands.
54scraping
Fetches web pages, parses HTML with CSS selectors, calls REST APIs, and scrapes dynamic content. Use when extracting data from websites, querying JSON APIs, or automating browser interactions.
48jscpd
Finds duplicate code blocks and analyzes duplication metrics across files. Use when identifying copy-pasted code, measuring technical debt, or preparing for refactoring.
45yt-dlp
Downloads videos from YouTube and other sites using yt-dlp. Use when downloading videos, extracting metadata, or batch downloading multiple files.
42