Add option that allows to rebalance panes (#59)

master
Ivan 3 years ago committed by GitHub
parent e81ece1e44
commit 6a55cc9603
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 {

@ -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

Loading…
Cancel
Save