jubnzv / go-tmux Goto Github PK
View Code? Open in Web Editor NEWA library to manage tmux sessions/windows/panes.
License: MIT License
A library to manage tmux sessions/windows/panes.
License: MIT License
Travis should be replaced, since it doesn't work properly in the current master
branch.
package main
import (
gotmux "github.com/jubnzv/go-tmux"
)
func main() {
server := new(gotmux.Server)
session := gotmux.Session{Name: "windows-panes"}
pane1 := gotmux.Pane{ID: 1}
pane2 := gotmux.Pane{ID: 2}
w1 := gotmux.Window{Name: "window-1", Id: 0}
w1.AddPane(pane1)
w1.AddPane(pane2)
w2 := gotmux.Window{Name: "window-2", Id: 1}
session.AddWindow(w1)
session.AddWindow(w2)
server.AddSession(session)
sessions := []*gotmux.Session{}
sessions = append(sessions, &session)
conf := gotmux.Configuration{
Server: server,
Sessions: sessions,
ActiveSession: nil,
}
err := conf.Apply()
if err != nil {
panic(err)
}
currentWindows, _ := session.ListWindows()
// select the first window
firstWindow := currentWindows[0]
firstWindow.Select()
// select the second pane in the first window
currentPanes, _ := firstWindow.ListPanes()
secondPane := currentPanes[1]
secondPane.Select()
err = session.AttachSession()
if err != nil {
panic(err)
}
}
package main
import (
"fmt"
gotmux "github.com/jubnzv/go-tmux"
)
func main() {
// Create instance of the running tmux server.
server := new(gotmux.Server)
// Prepare a configuration for the new session that contains some windows.
session := gotmux.Session{Name: "windows-panes", StartDirectory: "/tmp/"}
w := gotmux.Window{Name: "default-tmp", Id: 0}
session.AddWindow(w)
server.AddSession(session)
sessions := []*gotmux.Session{}
sessions = append(sessions, &session)
conf := gotmux.Configuration{
Server: server,
Sessions: sessions,
ActiveSession: nil,
}
// Setup this configuration.
err := conf.Apply()
if err != nil {
msg := fmt.Errorf("Can't apply prepared configuration: %s", err)
fmt.Println(msg)
return
}
currentWindows, _ := session.ListWindows()
for _, w := range currentWindows {
fmt.Printf("Current window: %v\n", w)
currentPanes, _ := w.ListPanes()
fmt.Printf("Current panes: %v\n", currentPanes)
fmt.Println()
}
// Attach to the created session
err = session.AttachSession()
if err != nil {
msg := fmt.Errorf("Can't attached to created session: %s", err)
fmt.Println(msg)
return
}
}
Current window: {default-tmp 1 0 windows-panes /madflow/go-tmux []}
I would expect the windows directory to be "/tmp/".
I running func (p *Pane) RunCommand(command string) error
is successful, when only exist one session.
But it may be failed when there is multi-session, because of can not find pane in window.
I guess pane index
should be used in Pane.RunCommand instead of p.ID(is pane globally unique id in reality)
๏ผ or modify command format after -t
ใ
In multi-session, the value of pane global unique id
may be beyond pane number of same window.
Considering the follwing example:
package main
import (
"fmt"
gotmux "github.com/jubnzv/go-tmux"
)
func main() {
// Create instance of the running tmux server.
server := new(gotmux.Server)
// Prepare a configuration for the new session that contains some windows.
session := gotmux.Session{Name: "windows-panes", StartDirectory: "/tmp/"}
w1 := gotmux.Window{Name: "first", Id: 0, StartDirectory: "/tmp/"}
w2 := gotmux.Window{Name: "second", Id: 1}
w2.AddPane(gotmux.Pane{
ID: 0,
})
w2.AddPane(gotmux.Pane{
ID: 1,
})
w2.AddPane(gotmux.Pane{
ID: 3,
})
session.AddWindow(w1)
session.AddWindow(w2)
server.AddSession(session)
sessions := []*gotmux.Session{}
sessions = append(sessions, &session)
conf := gotmux.Configuration{
Server: server,
Sessions: sessions,
ActiveSession: nil,
}
// Setup this configuration.
err := conf.Apply()
if err != nil {
msg := fmt.Errorf("Can't apply prepared configuration: %s", err)
fmt.Println(msg)
return
}
currentWindows, _ := session.ListWindows()
for _, w := range currentWindows {
fmt.Printf("Current window: %v\n", w)
currentPanes, _ := w.ListPanes()
fmt.Printf("Current panes: %v\n", currentPanes)
}
// Attach to the created session
err = session.AttachSession()
if err != nil {
msg := fmt.Errorf("Can't attached to created session: %s", err)
fmt.Println(msg)
return
}
}
This outputs
Current window: {first 29 0 windows-panes /private/tmp []}
Current panes: [{45 12 windows-panes 29 first 0 true} {46 12 windows-panes 30 second 1 false} {47 12 windows-panes 30 second 1 false} {48 12 windows-panes 30 second 1 true}]
Current window: {second 30 0 windows-panes /go-tmux []}
Current panes: [{45 12 windows-panes 29 first 0 true} {46 12 windows-panes 30 second 1 false} {47 12 windows-panes 30 second 1 false} {48 12 windows-panes 30 second 1 true}]
I would expect, that only Panes of the specific window should be returned.
Is this a "bug" and would a PR be acceptable?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.