✨ add support for panesthesia
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Close #12
This commit is contained in:
parent
b2a281d224
commit
468788594f
7
tmux/pane.go
Normal file
7
tmux/pane.go
Normal file
@ -0,0 +1,7 @@
|
||||
package tmux
|
||||
|
||||
type Pane struct {
|
||||
Root string `yaml:"root,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Commands []string `yaml:"commands,omitempty"`
|
||||
}
|
23
tmux/tmux.go
23
tmux/tmux.go
@ -9,6 +9,11 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const (
|
||||
VerticalSplit = "vertical"
|
||||
HorizontalSplit = "horizontal"
|
||||
)
|
||||
|
||||
type Tmux struct {
|
||||
BinPath string
|
||||
Debug bool
|
||||
@ -51,6 +56,24 @@ func (t *Tmux) Attach(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Tmux) SendKeys(target string, command string) error {
|
||||
_, err := t.Exec("send-keys", "-t", target, command, "Enter")
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *Tmux) SplitWindow(target string, split string, root string) error {
|
||||
args := []string{"split-window"}
|
||||
switch split {
|
||||
case VerticalSplit:
|
||||
args = append(args, "-v")
|
||||
case HorizontalSplit:
|
||||
args = append(args, "-h")
|
||||
}
|
||||
args = append(args, "-t", target, "-c", root)
|
||||
_, err := t.Exec(args...)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *Tmux) ListSessions() ([]string, error) {
|
||||
sessions := []string{}
|
||||
result, err := t.Exec("ls", "-F", "#{session_name}")
|
||||
|
@ -9,16 +9,29 @@ type Window struct {
|
||||
Root string `yaml:"root,omitempty"`
|
||||
Commands []string `yaml:"commands,omitempty"`
|
||||
ID string `yaml:"-"`
|
||||
Panes []Pane `yaml:"panes,omitempty"`
|
||||
}
|
||||
|
||||
func (w *Window) Create(tmux *Tmux) {
|
||||
tmux.Run("new-window", "-t", w.ID, "-n", w.Name, "-c", w.Root)
|
||||
|
||||
for i, pane := range w.Panes {
|
||||
if i > 0 {
|
||||
err := tmux.SplitWindow(w.ID, pane.Type, w.Root)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(pane.Commands) > 0 {
|
||||
tmux.SendKeys(w.ID, strings.Join(pane.Commands, ";"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) SendCommands(tmux *Tmux) {
|
||||
if len(w.Commands) > 0 {
|
||||
tmux.Run("send-keys", "-t", w.ID, strings.Join(w.Commands, ";"))
|
||||
tmux.Run("send-keys", "-t", w.ID, "Enter")
|
||||
tmux.SendKeys(w.ID, strings.Join(w.Commands, ";"))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user