diff --git a/config.go b/config.go index 6a5a21c..dd89d5e 100644 --- a/config.go +++ b/config.go @@ -27,11 +27,12 @@ type Window struct { } type Config struct { - Session string `yaml:"session"` - Root string `yaml:"root"` - BeforeStart []string `yaml:"before_start"` - Stop []string `yaml:"stop"` - Windows []Window `yaml:"windows"` + Session string `yaml:"session"` + Root string `yaml:"root"` + BeforeStart []string `yaml:"before_start"` + Stop []string `yaml:"stop"` + Windows []Window `yaml:"windows"` + RebalanceWindowsThreshold int `yaml:"rebalance_panes_after"` } func EditConfig(path string) error { diff --git a/smug.go b/smug.go index 32e8287..2de127c 100644 --- a/smug.go +++ b/smug.go @@ -9,6 +9,11 @@ import ( const defaultWindowName = "smug_def" +// Very wisely picked default value, +// after which panes will be rebalanced for each `split-window` +// Helps with "no space for new pane" error +const defaultRebalancePanesThreshold = 5 + func ExpandPath(path string) string { if strings.HasPrefix(path, "~/") { userHome, err := os.UserHomeDir() @@ -90,6 +95,11 @@ func (smug Smug) Start(config Config, options Options, context Context) error { windows := options.Windows attach := options.Attach + rebalancePanesThreshold := config.RebalanceWindowsThreshold + if rebalancePanesThreshold == 0 { + rebalancePanesThreshold = defaultRebalancePanesThreshold + } + if !sessionExists { err := smug.execShellCommands(config.BeforeStart, sessionRoot) if err != nil { @@ -126,13 +136,14 @@ func (smug Smug) Start(config Config, options Options, context Context) error { } } - for _, p := range w.Panes { + for pIndex, p := range w.Panes { paneRoot := ExpandPath(p.Root) if paneRoot == "" || !filepath.IsAbs(p.Root) { paneRoot = filepath.Join(windowRoot, p.Root) } newPane, err := smug.tmux.SplitWindow(window, p.Type, paneRoot) + if err != nil { return err } @@ -143,6 +154,14 @@ func (smug Smug) Start(config Config, options Options, context Context) error { return err } } + + if pIndex+1 >= rebalancePanesThreshold { + _, err = smug.tmux.SelectLayout(window, Tiled) + if err != nil { + return err + } + + } } layout := w.Layout