Documentation
¶
Overview ¶
Package gotmux is a simple library for interacting with tmux.
Index ¶
- func AddWindow(target string, name string) error
- func AddWindowWithIdx(target string, name string, idx uint8) error
- func Attach() error
- func AttachOrSwitchTo(target string) error
- func AttachTo(target string) error
- func Detach() error
- func GetCurrentSession() (string, error)
- func HasSession(target string) bool
- func IsInsideTmux() bool
- func IsTmuxInstalled() bool
- func KillServer() error
- func KillSession(target string) error
- func SwitchTo(target string) error
- func ValidateSessionName(name string) bool
- type Session
- type SessionConfig
- type TmuxCmd
- type TmuxError
- type TmuxList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddWindowWithIdx ¶
AddWindowWithIdx creates a new window in the specified tmux session with the given name and index.
func AttachOrSwitchTo ¶
AttachOrSwitchTo attaches to or switches to the specified tmux session. If inside a tmux session, it switches to the target session; otherwise, it attaches to it.
Warning: This action could replace the current process with tmux, ending the execution of the current program.
func AttachTo ¶
AttachTo attaches the current terminal to the specified tmux session.
Warning: This action will replace the current process with tmux, ending the execution of the current program.
func Detach ¶
func Detach() error
Detach detaches the current terminal from the tmux session.
Warning: This action will replace the current process with tmux, ending the execution of the current program.
func GetCurrentSession ¶
GetCurrentSession retrieves the name of the currently active tmux session.
func HasSession ¶
HasSession checks if a tmux session with the given name exists.
func IsInsideTmux ¶
func IsInsideTmux() bool
func IsTmuxInstalled ¶
func IsTmuxInstalled() bool
func KillServer ¶
func KillServer() error
KillServer terminates the tmux server, killing all sessions.
func KillSession ¶
KillSession terminates the specified tmux session.
func ValidateSessionName ¶
Types ¶
type Session ¶
type Session struct { Name string // Name of the tmux session Dir string // Working directory for the session }
Session represents a tmux session.
func NewSession ¶
func NewSession(config *SessionConfig) (*Session, error)
NewSession creates a new tmux session with the specified configuration. If the session name is invalid, an error is returned.
func (*Session) AddWindowWithIdx ¶
AddWindowWithIdx adds a new window with the specified name and index to the session.
func (*Session) AttachOrSwitch ¶
AttachOrSwitch attaches to the session if not already inside a tmux session, or switches to it if inside tmux.
type SessionConfig ¶
type SessionConfig struct { Name string // Name of the tmux session Dir string // Working directory for the session (optional) WindowName string // Name of the initial window in the session (optional) }
SessionConfig holds the configuration options for creating a new tmux session.
type TmuxCmd ¶
type TmuxCmd struct {
// contains filtered or unexported fields
}
TmuxCmd represents a tmux command with its path and arguments.
func NewTmuxCmd ¶
NewTmuxCmd creates a new TmuxCmd instance with the given arguments. It looks up the tmux executable path and returns an error if tmux is not found.
func (*TmuxCmd) Exec ¶
Exec executes the tmux command without returning its output. It returns an error if the command execution fails.
func (*TmuxCmd) ExecSyscall ¶
ExecSyscall replaces the current process with a new tmux process. It uses the syscall.Exec function to execute tmux with the given arguments. This function does not return unless there's an error in starting the new process.
func (*TmuxCmd) ExecWithOutput ¶
ExecWithOutput executes the tmux command and returns its output as a string. It returns both the output and an error if the command execution fails.
type TmuxError ¶
type TmuxError int
TmuxError represents different types of errors that can occur with tmux commands.
const ( Unknown TmuxError = iota // An unknown error occurred SessionNotCreated // The session could not be created NestedSession // Sessions should be nested with care DuplicateSession // The session name is duplicated SessionNotFound // The session was not found CommandFailed // The command failed to execute InvalidArgument // An invalid argument was provided PermissionDenied // Permission was denied Timeout // The command timed out )
func IdentifyError ¶
IdentifyError classifies the error based on the command output.
type TmuxList ¶
type TmuxList struct { Output string // Output contains the raw string output from a tmux command. // contains filtered or unexported fields }
TmuxList represents the output of a tmux command and its error state.
func ListSessions ¶
ListSessions lists all tmux sessions with an optional custom format.
func ListWindows ¶
ListWindows lists all windows in the specified tmux session with an optional custom format.