A comprehensive Go library for programmatically interacting with tmux sessions, windows, and panes. gotmux provides a clean, type-safe interface to manage tmux through Go, making it easy to automate terminal multiplexing tasks and build tmux-based applications.
- Complete tmux Integration: Full access to tmux sessions, windows, and panes
- Type-Safe API: Strongly typed structures for all tmux entities
- Comprehensive Data Access: Retrieve all tmux fields and properties
- Session Management: Create, rename, delete, and manage sessions
- Window Operations: Handle windows, layouts, and navigation
- Pane Control: Split, resize, and manage panes programmatically
- Server Information: Query tmux server status and client connections
- Error Handling: Robust error handling throughout the API
- Go 1.22.3 or later
- tmux installed on your system
go get github.com/GianlucaP106/gotmux
package main
import (
"log"
"github.com/GianlucaP106/gotmux/gotmux"
)
func main() {
// Initialize tmux client
tmux, err := gotmux.DefaultTmux()
if err != nil {
log.Fatal(err)
}
// Create a new session
session, err := tmux.New()
if err != nil {
log.Fatal(err)
}
// Attach to the session
err = session.Attach()
if err != nil {
log.Fatal(err)
}
}
Create and manage tmux sessions with full control over their properties:
// Create a new session with custom options
session, err := tmux.NewSession(&gotmux.SessionOptions{
StartDirectory: "/home/user",
Name: "my-session",
})
// List all sessions
sessions, err := tmux.ListSessions()
// Attach to a session
err = session.Attach()
// Rename a session
err = session.Rename("new-name")
Manage windows within sessions:
// Create a new window
window, err := session.New()
// Get window by index
window, err := session.GetWindowByIndex(0)
// Select a specific layout
err = window.SelectLayout(gotmux.WindowLayoutEvenVertical)
// Move window to another session
err = window.MoveWindow(targetSession)
Control individual panes within windows:
// Get pane by index
pane, err := window.GetPaneByIndex(0)
// Split pane horizontally
err = pane.Split()
// Split pane vertically
err = pane.SplitVertical()
// Resize pane
err = pane.Resize(10, 20)
// Execute command in pane
err = pane.SendKeys("ls -la")
Query tmux server status and connected clients:
// Get server information
server, err := tmux.GetServerInformation()
fmt.Printf("tmux version: %s\n", server.Version)
// List connected clients
clients, err := tmux.ListClients()
for _, client := range clients {
fmt.Printf("Client: %s, Session: %s\n", client.Tty, client.Session)
}
gotmux provides comprehensive data structures that capture all tmux fields. For example, the Session struct includes:
type Session struct {
Activity string // Last activity time
Alerts string // Alert flags
Attached int // Number of attached clients
AttachedList []string // List of attached clients
Created string // Creation time
Format bool // Format flag
Group string // Session group
GroupAttached int // Number of attached clients in group
GroupAttachedList []string // List of attached clients in group
GroupList []string // List of sessions in group
GroupManyAttached bool // Multiple clients attached to group
GroupSize int // Number of sessions in group
Grouped bool // Whether session is grouped
Id string // Session ID
LastAttached string // Last attachment time
ManyAttached bool // Multiple clients attached
Marked bool // Marked flag
Name string // Session name
Path string // Working directory
Stack string // Stack information
Windows int // Number of windows
}
The project includes comprehensive examples in the examples/
directory:
- create/: Basic session, window, and pane creation
- sessions/: Session management operations
- windows_panes/: Window and pane manipulation
- listing/: Querying and listing tmux entities
- get_server_info/: Server information retrieval
- list_clients/: Client connection management
func main() {
tmux, err := gotmux.DefaultTmux()
if err != nil {
log.Fatal(err)
}
// Create session with specific options
session, err := tmux.NewSession(&gotmux.SessionOptions{
StartDirectory: "/home/user/projects",
Name: "development",
})
if err != nil {
log.Fatal(err)
}
// Create a window and split it
window, err := session.New()
if err != nil {
log.Fatal(err)
}
pane, err := window.GetPaneByIndex(0)
if err != nil {
log.Fatal(err)
}
// Split the pane and execute commands
err = pane.Split()
if err != nil {
log.Fatal(err)
}
err = pane.SendKeys("cd /home/user/projects && ls -la")
if err != nil {
log.Fatal(err)
}
}
- API Reference: pkg.go.dev
- Examples: examples directory
- Source Code: GitHub repository
Contributions are welcome! The project aims to provide complete tmux functionality through Go. Please feel free to:
- Report bugs or request features
- Submit pull requests
- Improve documentation
- Add new examples
gotmux is actively developed and aims to provide complete tmux functionality. While not all tmux features are implemented yet, the core functionality is stable and ready for production use.
This project is licensed under the MIT License - see the LICENSE file for details.
- Built for the Go community
- Inspired by the power and flexibility of tmux
- Designed for automation and programmatic terminal management
Start building powerful tmux applications with Go today!