diff --git a/README.md b/README.md index a8e478f..690498b 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ windows: - name: code root: blog # a relative path to root manual: true # you can start this window only manually, using the -w arg + layout: main-vertical commands: - docker-compose start panes: @@ -91,6 +92,7 @@ windows: - name: infrastructure root: ~/Developer/blog/my-microservices + layout: tiled panes: - type: horizontal root: . @@ -114,6 +116,7 @@ stop: windows: - name: code + layout: main-horizontal commands: - vim app/dependencies.php panes: diff --git a/config.go b/config.go index 2ba7b89..0735ff6 100644 --- a/config.go +++ b/config.go @@ -14,7 +14,8 @@ type Window struct { BeforeStart []string `yaml:"before_start"` Panes []Pane `yaml:"panes"` Commands []string `yaml:"commands"` - Manual bool + Layout string `yaml:"layout"` + Manual bool `yaml:"manual"` } type Config struct { diff --git a/smug.go b/smug.go index fab9f6e..2026926 100644 --- a/smug.go +++ b/smug.go @@ -119,6 +119,16 @@ func (smug Smug) Start(config Config, windows []string) error { return err } } + + layout := w.Layout + if layout == "" { + layout = EvenHorizontal + } + + _, err = smug.tmux.SelectLayout(ses+w.Name, layout) + if err != nil { + return err + } } if len(windows) == 0 { diff --git a/smug_test.go b/smug_test.go index 4a76a34..d8c65cb 100644 --- a/smug_test.go +++ b/smug_test.go @@ -41,10 +41,17 @@ var testTable = []struct { { Name: "win1", Manual: false, + Layout: "main-horizontal", + Panes: []Pane{ + Pane{ + Type: "horizontal", + }, + }, }, { Name: "win2", Manual: true, + Layout: "tiled", }, }, Stop: []string{ @@ -56,6 +63,8 @@ var testTable = []struct { "tmux has-session -t ses", "tmux new -Pd -s ses", "tmux neww -Pd -t ses: -n win1 -c root", + "tmux split-window -Pd -t ses: -c root -h", + "tmux select-layout -t ses:win1 main-horizontal", "tmux kill-window -t ses:0", "tmux move-window -r", "tmux attach -t ses:0", @@ -86,6 +95,7 @@ var testTable = []struct { "tmux has-session -t ses", "tmux new -Pd -s ses", "tmux neww -Pd -t ses: -n win2 -c root", + "tmux select-layout -t ses:win2 even-horizontal", }, []string{ "tmux kill-window -t ses:win2", diff --git a/tmux.go b/tmux.go index a8b135c..b4e997b 100644 --- a/tmux.go +++ b/tmux.go @@ -10,6 +10,14 @@ const ( HSplit = "horizontal" ) +const ( + EvenHorizontal = "even-horizontal" + EvenVertical = "even-vertical" + MainHorizontal = "main-horizontal" + MainVertical = "main-vertical" + Tiled = "tiled" +) + type Tmux struct { commander Commander } @@ -98,6 +106,11 @@ func (tmux Tmux) SplitWindow(target string, splitType string, root string, comma return pane, nil } +func (tmux Tmux) SelectLayout(target string, layoutType string) (string, error) { + cmd := exec.Command("tmux", "select-layout", "-t", target, layoutType) + return tmux.commander.Exec(cmd) +} + func (tmux Tmux) StopSession(target string) (string, error) { cmd := exec.Command("tmux", "kill-session", "-t", target) return tmux.commander.Exec(cmd)