gomux

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

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

Go to latest
Published: Nov 25, 2019 License: Apache-2.0 Imports: 3 Imported by: 2

README

gomux

Build Status Coverage Status GoDoc

Go wrapper to create tmux sessions, windows and panes.

Example

example.go:

package main
import (
	"os"
	"github.com/wricardo/gomux"
)
func main() {
	session_name := "SESSION_NAME"

	s := gomux.NewSession(session_name, os.Stdout)

	//WINDOW 1
	w1 := s.AddWindow("Monitoring")

	w1p0 := w1.Pane(0)
	w1p0.Exec("htop")

	w1p1 := w1.Pane(0).Split()
	w1p1.Exec("tail -f /var/log/syslog")

	//WINDOW 2
	w2 := s.AddWindow("Vim")
	w2p0 := w2.Pane(0)

	w2p0.Exec("echo \"this is to vim\" | vim -")

	w2p1 := w2p0.Vsplit()
	w2p1.Exec("cd /tmp/")
	w2p1.Exec("ls -la")

	w2p0.ResizeRight(30)
	w1.Select()
}

To print the tmux commands:

go run example.go 
tmux new-session -d -s "SESSION_NAME" -n tmp
tmux rename-window -t "SESSION_NAME:0" "Monitoring"
tmux send-keys -t "SESSION_NAME:0.0" "htop" C-m
tmux split-window -v -t "SESSION_NAME:0.0"
tmux send-keys -t "SESSION_NAME:0.1" "tail -f /var/log/syslog" C-m
tmux new-window -t "SESSION_NAME:1" -n "Vim"
tmux rename-window -t "SESSION_NAME:1" "Vim"
tmux send-keys -t "SESSION_NAME:1.0" "echo \"this is to vim\" | vim -" C-m
tmux split-window -h -t "SESSION_NAME:1.0"
tmux send-keys -t "SESSION_NAME:1.1" "cd /tmp/" C-m
tmux send-keys -t "SESSION_NAME:1.1" "ls -la" C-m
tmux resize-pane -t "SESSION_NAME:1.0" -R 30
tmux select-window -t "SESSION_NAME:0"

To create and attach to the tmux session:

go run example.go | bash
tmux attach -t SESSION_NAME

example screenshot

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KillSession

func KillSession(name string, writer io.Writer)

KillSession sends a command to kill the tmux session

Types

type Pane

type Pane struct {
	Number int
	// contains filtered or unexported fields
}

func NewPane

func NewPane(number int, window *Window) *Pane

func (*Pane) Exec

func (this *Pane) Exec(command string)

func (*Pane) ResizeDown

func (this *Pane) ResizeDown(num int)

func (*Pane) ResizeLeft

func (this *Pane) ResizeLeft(num int)

func (*Pane) ResizeRight

func (this *Pane) ResizeRight(num int)

func (*Pane) ResizeUp

func (this *Pane) ResizeUp(num int)

func (*Pane) Split

func (this *Pane) Split() *Pane

func (*Pane) SplitWAttr

func (this *Pane) SplitWAttr(attr SplitAttr) *Pane

func (*Pane) Vsplit

func (this *Pane) Vsplit() *Pane

func (*Pane) VsplitWAttr

func (this *Pane) VsplitWAttr(attr SplitAttr) *Pane

type Session

type Session struct {
	Name      string
	Directory string
	// contains filtered or unexported fields
}

Session represents a tmux session.

Use the method NewSession to create a Session instance.

func NewSession

func NewSession(name string, writer io.Writer) *Session

Creates a new Tmux Session. It will kill any existing session with the provided name.

func NewSessionAttr

func NewSessionAttr(p SessionAttr, writer io.Writer) *Session

Creates a new Tmux Session based on NewSessionAttr. It will kill any existing session with the provided name.

func (*Session) AddWindow

func (this *Session) AddWindow(name string) *Window

Creates window with provided name for this session

func (*Session) AddWindowAttr

func (this *Session) AddWindowAttr(attr WindowAttr) *Window

Creates window with provided name for this session

type SessionAttr

type SessionAttr struct {
	Name      string
	Directory string
}

type SplitAttr

type SplitAttr struct {
	Directory string
}

type Window

type Window struct {
	Number    int
	Name      string
	Directory string
	// contains filtered or unexported fields
}

Window Represent a tmux window. You usually should not create an instance of Window directly.

func (*Window) AddPane

func (this *Window) AddPane(withNumber int) *Pane

Create a new Pane and add to this window

func (*Window) Exec

func (this *Window) Exec(command string)

Executes a command on the first pane of this window

// example // example

func (*Window) Pane

func (this *Window) Pane(number int) *Pane

Find and return the Pane object by its index in the panes slice

func (*Window) Select

func (this *Window) Select()

type WindowAttr

type WindowAttr struct {
	Name      string
	Directory string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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