From c07add3bef0c99c694e886cb87cb66156ea1a529 Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 1 Feb 2021 21:47:54 +0200 Subject: [PATCH] [WIP] Bugfix/split layout is not working correctly (#33) * [bugfix] fix options order in split-layout command --- main.go | 2 +- smug.go | 6 ++++-- smug_test.go | 4 ++-- tmux.go | 4 +++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 7e7013e..474ff34 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ import ( "path/filepath" ) -const version = "v0.1.7" +const version = "v0.1.8" var usage = fmt.Sprintf(`Smug - tmux session manager. Version %s diff --git a/smug.go b/smug.go index b929de6..f0589fc 100644 --- a/smug.go +++ b/smug.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "os" "os/exec" "path/filepath" @@ -137,13 +138,14 @@ func (smug Smug) Start(config Config, options Options, context Context) error { return err } - 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) + target := fmt.Sprintf("%s.%d", window, pIndex) + newPane, err := smug.tmux.SplitWindow(target, p.Type, paneRoot) if err != nil { return err } diff --git a/smug_test.go b/smug_test.go index 87a0505..f52408d 100644 --- a/smug_test.go +++ b/smug_test.go @@ -79,7 +79,7 @@ var testTable = []struct { "tmux new -Pd -s ses -n smug_def -c root", "tmux neww -Pd -t ses: -n win1 -c root", "tmux select-layout -t ses:win1 main-horizontal", - "tmux split-window -Pd -t ses:win1 -c root -F #{pane_id} -h", + "tmux split-window -Pd -h -t ses:win1.0 -c root -F #{pane_id}", "tmux kill-window -t ses:smug_def", "tmux move-window -r -s ses: -t ses:", "tmux attach -d -t ses:win1", @@ -192,7 +192,7 @@ var testTable = []struct { "tmux new -Pd -s ses -n smug_def -c root", "tmux neww -Pd -t ses: -n win1 -c root/win1", "tmux select-layout -t ses:win1 even-horizontal", - "tmux split-window -Pd -t ses:win1 -c root/win1/pane1 -F #{pane_id} -v", + "tmux split-window -Pd -v -t ses:win1.0 -c root/win1/pane1 -F #{pane_id}", "tmux send-keys -t ses:win1.1 command1 Enter", "tmux kill-window -t ses:smug_def", "tmux move-window -r -s ses: -t ses:", diff --git a/tmux.go b/tmux.go index d8730cc..cb7a569 100644 --- a/tmux.go +++ b/tmux.go @@ -67,7 +67,7 @@ func (tmux Tmux) RenumberWindows(target string) error { } func (tmux Tmux) SplitWindow(target string, splitType string, root string) (string, error) { - args := []string{"split-window", "-Pd", "-t", target, "-c", root, "-F", "#{pane_id}"} + args := []string{"split-window", "-Pd"} switch splitType { case VSplit: @@ -76,6 +76,8 @@ func (tmux Tmux) SplitWindow(target string, splitType string, root string) (stri args = append(args, "-h") } + args = append(args, []string{"-t", target, "-c", root, "-F", "#{pane_id}"}...) + cmd := exec.Command("tmux", args...) pane, err := tmux.commander.Exec(cmd)