tmux

package module
v0.0.0-...-05b8c9b Latest Latest
Warning

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

Go to latest
Published: May 14, 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)

Return name of 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
}

func ListPanes

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

Return 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 (*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) GetCurrentSize

func (p *Pane) GetCurrentSize() (int, int, error)

func (*Pane) MovePane

func (p *Pane) MovePane(pane_target *Pane, focus bool) error

func (*Pane) RunCommand

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

RunCommand runs a command in the pane.

func (*Pane) SetFocus

func (p *Pane) SetFocus() error

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
}

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)

List 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 {
	Name           string   // Session name
	Id             int      // Session id
	StartDirectory string   // Path to window start directory
	Windows        []Window // List of windows used on session initialization
}

func (*Session) AddWindow

func (s *Session) AddWindow(window Window)

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

func (*Session) AttachSession

func (s *Session) AttachSession() error

Attach to existing tmux session.

func (*Session) DettachSession

func (s *Session) DettachSession() error

Detach from current session.

func (*Session) InitSession

func (s *Session) InitSession() error

func (*Session) ListPanes

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

Return list with all panes for this session.

func (*Session) ListWindows

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

List all windows in the current session.

func (*Session) NewWindow

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

Create a new window.

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
}

func (*Window) AddPane

func (w *Window) AddPane(pane Pane)

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

func (*Window) ListPanes

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

Return 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