tmux

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const SessionName = "kage"

Variables

This section is empty.

Functions

func AttachSession

func AttachSession() error

AttachSession replaces the current process with tmux attach-session. This uses syscall.Exec so the Go process is replaced entirely.

func CalcRelativeSplitSizes

func CalcRelativeSplitSizes(panes []int) []int

CalcRelativeSplitSizes computes the tmux split percentages needed to achieve the desired absolute layout. tmux splits are relative to the remaining space. For example, [60%, 20%, 20%] → the first pane gets 60%. The remaining 40% is split: 20/40 = 50% for the second, leaving 20/20 = 100% (no split needed). Returns the percentage for each split operation (first pane is the initial window, so we return n-1 values for n panes).

func CapturePane

func CapturePane(target string, lines int) (string, error)

CapturePane captures visible content from a tmux pane. If lines > 0, only the last N lines are captured.

func HasSession

func HasSession() bool

HasSession checks if the kage tmux session exists.

func InsideTmux

func InsideTmux() bool

InsideTmux returns true if the current process is inside a tmux session.

func KillWindow

func KillWindow(target string) error

KillWindow destroys a window.

func NewSession

func NewSession(startDir string) error

NewSession creates a new tmux session named "kage" in detached mode. The first window is named "dashboard". If startDir is non-empty, the session starts in that directory.

func NewWindow

func NewWindow(name string, startDir string, detached bool) error

NewWindow creates a new window in the kage session. If detached is true, the window is created without switching to it.

func NewWindowWithCmd

func NewWindowWithCmd(name string, startDir string, detached bool, cmd string) error

NewWindowWithCmd creates a new window and runs a command directly in it. Unlike NewWindow + SendKeys, this avoids the race condition where keystrokes arrive before the shell is ready.

func ParseSizePercent

func ParseSizePercent(s string) int

ParseSizePercent extracts the integer from a percentage string like "60%".

func Run

func Run(args ...string) (string, error)

Run executes a tmux command and returns its output.

func RunSilent

func RunSilent(args ...string) error

RunSilent executes a tmux command without capturing output.

func SelectWindow

func SelectWindow(window string) error

SelectWindow switches to a specific window in the kage session.

func SendKeys

func SendKeys(target string, keys string) error

SendKeys sends keystrokes to a tmux pane.

func SendKeysLiteral

func SendKeysLiteral(target string, text string) error

SendKeysLiteral sends literal text to a tmux pane (no special key interpretation).

func SetupLayoutTree

func SetupLayoutTree(windowTarget string, node *config.LayoutNode, paneTarget string, workDir string, initialCmdHandled bool) error

SetupLayoutTree creates panes according to a recursive layout tree. windowTarget is like "kage:1", paneTarget is like "kage:1.0". If initialCmdHandled is true, the first leaf pane's command was already started (e.g. via NewWindowWithCmd) and should not be sent again.

func SplitWindow

func SplitWindow(target string, horizontal bool, size string, startDir string) error

SplitWindow splits a pane. If horizontal is true, splits top/bottom (-v flag in tmux). size is a percentage string like "20%".

func SplitWindowWithCmd

func SplitWindowWithCmd(target string, horizontal bool, size string, startDir string, cmd string, detached bool) error

SplitWindowWithCmd splits a pane and runs a command directly in the new pane. Unlike SplitWindow + SendKeys, this avoids the race condition where keystrokes arrive before the shell is ready. The pane is set to remain-on-exit so it stays open if the command exits. If detached is true, the original pane retains focus.

func SwitchClient

func SwitchClient() error

SwitchClient switches the current tmux client to the kage session.

Types

type PaneInfo

type PaneInfo struct {
	Index          int
	CurrentCommand string
}

PaneInfo represents a tmux pane.

func ListPanes

func ListPanes(windowTarget string) ([]PaneInfo, error)

ListPanes returns all panes in a specific window.

type WindowInfo

type WindowInfo struct {
	Index string
	Name  string
}

WindowInfo represents a tmux window.

func ListWindows

func ListWindows() ([]WindowInfo, error)

ListWindows returns all windows in the kage session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL