tmux

package module
v0.0.0-...-d8ec54c Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 9 Imported by: 0

README

go-tmux

Build Status codecov GoDoc

A library to manage tmux sessions/windows/panes.

Usage

See examples directory:

  • create_session – Example that shows how to create a tmux session with user-defined configuration
  • sessions_manager – Sessions manager implemented using this library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecCmd

func ExecCmd(args []string) error

Execute tmux command using syscall execve(2).

func GetAttachedSessionName

func GetAttachedSessionName() (string, error)

Returns a name of the attached tmux session.

func InTravis

func InTravis() bool

func IsInsideTmux

func IsInsideTmux() bool

Returns true if executed inside tmux, false otherwise.

func RunCmd

func RunCmd(args []string) (string, string, error)

Wrapper to tmux CLI that execute command with given arguments and returns stdout and stderr output.

Types

type Configuration

type Configuration struct {
	Server        *Server    // Pointer to used tmux server
	Sessions      []*Session // List of sessions to be initialized
	ActiveSession *Session   // Session to be attached after initialization.

}

func (*Configuration) Apply

func (c *Configuration) Apply() error

Apply given configuration to setup a user-defined workflow Before running this method, user must make sure that there is no windows and session with same names exists. Otherwise existing sessions/windows will be replaced with the new ones.

type Pane

type Pane struct {
	ID          int
	SessionId   int
	SessionName string
	WindowId    int
	WindowName  string
	WindowIndex int
	Active      bool
}

Represent a tmux pane: https://github.com/tmux/tmux/wiki/Getting-Started#sessions-windows-and-panes

func ListPanes

func ListPanes(args []string) ([]Pane, error)

Return a list of panes. Optional arguments are define the search scope with tmux command keys (see tmux(1) manpage):

list-panes [-as] [-F format] [-t target]

  • `-a`: target is ignored and all panes on the server are listed
  • `-s`: target is a session. If neither is given, target is a window (or the current window).

func NewPane

func NewPane(id int, sessionId int, sessionName string, windowId int,
	windowName string, windowIndex int, active bool) *Pane

Creates a new pane object.

func (*Pane) Capture

func (p *Pane) Capture() (string, error)

func (*Pane) GetCurrentPath

func (p *Pane) GetCurrentPath() (string, error)

Returns current path for this pane.

func (*Pane) RunCommand

func (p *Pane) RunCommand(command string) error

RunCommand runs a command in the pane.

type Server

type Server struct {
	SocketPath string    // Path to tmux server socket
	SocketName string    // Name of created tmux socket
	Sessions   []Session // List of sessions used on server initialization
}

Represents a tmux server: https://github.com/tmux/tmux/wiki/Getting-Started#the-tmux-server-and-clients

func NewServer

func NewServer(socketPath, socketName string, sessions []Session) *Server

Creates a new server object.

func (*Server) AddSession

func (s *Server) AddSession(session Session)

Add session to server configuration. This will change only in-library server representation. Used for initial configuration before creating new server.

func (*Server) HasSession

func (s *Server) HasSession(name string) (bool, error)

Return true that session with given name is exsits on this server, false otherwise.

func (*Server) KillSession

func (s *Server) KillSession(name string) error

Kills session with given name. If killed session not found, KillSession will not raise error and just do nothing.

func (*Server) ListPanes

func (s *Server) ListPanes() ([]Pane, error)

Return list with all panes managed by this server.

func (*Server) ListSessions

func (s *Server) ListSessions() ([]Session, error)

Lists all sessions managed by this server.

func (*Server) NewSession

func (s *Server) NewSession(name string) (session Session, err error)

Create new session with given name on this server.

Session always will be detached after creation. Call AttachSession to attach it. If session already exists, this function return an error. Check session with HaveSession before running it if you need it.

type Session

type Session struct {
	Id             int      // Session id
	Name           string   // Session name
	StartDirectory string   // Path to window start directory
	Windows        []Window // List of windows used on session initialization
}

Represents a tmux session: https://github.com/tmux/tmux/wiki/Getting-Started#sessions-windows-and-panes

func NewSession

func NewSession(id int, name, startDirectory string, windows []Window) *Session

Creates a new session object.

func (*Session) AddWindow

func (s *Session) AddWindow(window Window)

Adds the window to the session configuration. This will change only in-library session representation. Used for initial configuration before creating a new session.

func (*Session) AttachSession

func (s *Session) AttachSession() error

Attach to existing tmux session.

func (*Session) DettachSession

func (s *Session) DettachSession() error

Detaches from the current session. Detaching from the tmux session means that the client exits and detaches from the outside terminal. See: https://github.com/tmux/tmux/wiki/Getting-Started#attaching-and-detaching

func (*Session) ListPanes

func (s *Session) ListPanes() ([]Pane, error)

Returns list with all panes for this session.

func (*Session) ListWindows

func (s *Session) ListWindows() ([]Window, error)

Lists all windows in the current session.

func (*Session) NewWindow

func (s *Session) NewWindow(name string) (window Window, err error)

Creates a new window inside this session.

type Window

type Window struct {
	Name           string
	Id             int
	SessionId      int
	SessionName    string
	StartDirectory string // Path to window working directory
	Panes          []Pane // List of panes used in initial window configuration
}

Represents a tmux window: https://github.com/tmux/tmux/wiki/Getting-Started#sessions-windows-and-panes

func NewWindow

func NewWindow(id int, name string, sessionId int, sessionName string, startDirectory string, panes []Pane) *Window

Creates a new window object.

func (*Window) AddPane

func (w *Window) AddPane(pane Pane)

Adds the pane to the window configuration. This will change only in-library window representation. Used for initial configuration before creating a new window.

func (*Window) ListPanes

func (w *Window) ListPanes() ([]Pane, error)

Returns a list with all panes for this window.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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