Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use last pane id for splitting windows #35

Merged
merged 4 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions smug.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -138,18 +137,20 @@ func (smug Smug) Start(config Config, options Options, context Context) error {
return err
}

for pIndex, p := range w.Panes {
var lastPane string
for _, p := range w.Panes {
paneRoot := ExpandPath(p.Root)
if paneRoot == "" || !filepath.IsAbs(p.Root) {
paneRoot = filepath.Join(windowRoot, p.Root)
}

target := fmt.Sprintf("%s.%d", window, pIndex)
newPane, err := smug.tmux.SplitWindow(target, p.Type, paneRoot)
newPane, err := smug.tmux.SplitWindow(window+"."+lastPane, p.Type, paneRoot)
if err != nil {
return err
}

lastPane = newPane

for _, c := range p.Commands {
err = smug.tmux.SendKeys(window+"."+newPane, c)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions smug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -h -t ses:win1.0 -c root -F #{pane_id}",
"tmux split-window -Pd -h -t ses:win1. -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",
Expand Down Expand Up @@ -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 -v -t ses:win1.0 -c root/win1/pane1 -F #{pane_id}",
"tmux split-window -Pd -v -t ses:win1. -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:",
Expand Down