#8 Always kill first window from list-windows command (#9)

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

@ -132,7 +132,12 @@ func (smug Smug) Start(config Config, windows []string) error {
} }
if len(windows) == 0 { if len(windows) == 0 {
err = smug.tmux.KillWindow(ses + "0") windows, err := smug.tmux.ListWindows(ses)
if err != nil {
return err
}
err = smug.tmux.KillWindow(ses + windows[0])
if err != nil { if err != nil {
return err return err
} }

@ -24,7 +24,8 @@ var testTable = []struct {
"/bin/sh -c command1", "/bin/sh -c command1",
"/bin/sh -c command2", "/bin/sh -c command2",
"tmux new -Pd -s ses", "tmux new -Pd -s ses",
"tmux kill-window -t ses:0", "tmux list-windows -t ses: -F #{window_index}",
"tmux kill-window -t ses:ses:",
"tmux move-window -r", "tmux move-window -r",
"tmux attach -t ses:0", "tmux attach -t ses:0",
}, },
@ -65,7 +66,8 @@ var testTable = []struct {
"tmux neww -Pd -t ses: -n win1 -c root", "tmux neww -Pd -t ses: -n win1 -c root",
"tmux split-window -Pd -t ses: -c root -h", "tmux split-window -Pd -t ses: -c root -h",
"tmux select-layout -t ses:win1 main-horizontal", "tmux select-layout -t ses:win1 main-horizontal",
"tmux kill-window -t ses:0", "tmux list-windows -t ses: -F #{window_index}",
"tmux kill-window -t ses:ses:",
"tmux move-window -r", "tmux move-window -r",
"tmux attach -t ses:0", "tmux attach -t ses:0",
}, },

@ -3,6 +3,7 @@ package main
import ( import (
"os" "os"
"os/exec" "os/exec"
"strings"
) )
const ( const (
@ -115,3 +116,14 @@ func (tmux Tmux) StopSession(target string) (string, error) {
cmd := exec.Command("tmux", "kill-session", "-t", target) cmd := exec.Command("tmux", "kill-session", "-t", target)
return tmux.commander.Exec(cmd) return tmux.commander.Exec(cmd)
} }
func (tmux Tmux) ListWindows(target string) ([]string, error) {
cmd := exec.Command("tmux", "list-windows", "-t", target, "-F", "#{window_index}")
output, err := tmux.commander.Exec(cmd)
if err != nil {
return []string{}, err
}
return strings.Split(output, "\n"), nil
}

Loading…
Cancel
Save