272 lines · 7.4 KB · executable
#!/usr/bin/env bash
set -euo pipefail

# Manage tmux sessions, windows, and panes.
#
# Usage:
#   tmux_session.sh <command> [options]
#
# Commands:
#   new [name] [workdir]              Create new session (optionally named, in workdir)
#   kill [session]                    Kill session
#   list                              List sessions with windows and panes
#   list-sessions                      List session names only
#   list-windows [session]             List windows in a session
#   list-panes [session:window]       List panes with index, title, command
#   split [target] [-h|-v] [workdir]   Split pane (horizontal or vertical)
#   new-window [session] [name] [workdir]  Create new window
#   kill-window [session:window]       Kill window
#   kill-pane [target]                 Kill a pane
#   select [target]                    Select a pane/window/session
#   rename [target] [name]             Rename a session or window
#   resize [target] [-L|-R|-U|-D] [n]  Resize pane by n cells
#   zoom [target]                      Toggle zoom on a pane
#   break-pane [target] [session]      Break pane into its own window
#   info [target]                      Show detailed info about a pane
#   exists [session]                   Check if session exists (exit 0/1)
#   attached [session]                 Check if session is attached (exit 0/1)
#   -h, --help                         Show this help

usage() {
	sed -n '4,/^$/p' "$0" | sed 's/^# \?//' >&2
	exit 1
}

[[ $# -lt 1 ]] && usage

CMD="$1"
shift

case "$CMD" in