Skip to content

Commit 4a06096

Browse files
committed
Added "restart" command line option.
The "restart" option will cause the "KillCmd" to be executed for each Pane that has one. Then, for those same Panes, their Cmd will be run again.
1 parent 19497f0 commit 4a06096

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010

1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
13+
14+
# Vim files
15+
*.sw[op]
16+
17+
tmux-compose

main.go

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
)
1414

1515
type Pane struct {
16-
Object `yaml:",inline"`
17-
Dir string
18-
Focus bool
19-
Cmd string
20-
target string
16+
Object `yaml:",inline"`
17+
Dir string
18+
Focus bool
19+
Cmd string
20+
KillCmd string `yaml:"kill_cmd"`
21+
target string
2122
}
2223

2324
type Window struct {
@@ -38,6 +39,8 @@ type Project struct {
3839
Windows []*Window
3940
}
4041

42+
var gRestart bool
43+
4144
func run(format string, args ...interface{}) error {
4245
cmdStr := fmt.Sprintf(format, args...)
4346
cmd := exec.Command("/bin/sh", "-c", cmdStr)
@@ -132,6 +135,9 @@ func (project *Project) getDir(w *Window, paneIndex int) string {
132135
}
133136

134137
func (p *Pane) Run() {
138+
if gRestart && p.KillCmd == "" {
139+
return
140+
}
135141
SendLine(p.target, p.Cmd)
136142
}
137143

@@ -254,6 +260,44 @@ func down(session string, project *Project) {
254260
}
255261
}
256262

263+
func restart(session string, project *Project) {
264+
// Run the commands concurrently
265+
for wi, w := range project.Windows {
266+
if w == nil {
267+
continue
268+
}
269+
for pi, p := range w.Panes {
270+
if p == nil {
271+
continue
272+
}
273+
p.target = fmt.Sprintf("%s:%d.%d", session, wi, pi)
274+
275+
if p.KillCmd != "" {
276+
SendLine(p.target, p.KillCmd)
277+
}
278+
}
279+
}
280+
281+
// Used in each Panel's Run() method to know if we are performing a restart.
282+
// Only commands with a KillCmd will be restarted.
283+
gRestart = true
284+
285+
// Run the commands concurrently
286+
for _, w := range project.Windows {
287+
if w == nil {
288+
continue
289+
}
290+
addRunner(w)
291+
for _, p := range w.Panes {
292+
if p == nil {
293+
continue
294+
}
295+
addRunner(p)
296+
}
297+
}
298+
runAll()
299+
}
300+
257301
func main() {
258302
var overrideName string
259303
var composeFile string
@@ -286,5 +330,7 @@ func main() {
286330
up(session, &project)
287331
case "down":
288332
down(session, &project)
333+
case "restart":
334+
restart(session, &project)
289335
}
290336
}

test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ windows:
77
layout: main-vertical
88
focus: true
99
panes:
10-
- cmd: vim
10+
- cmd: top
11+
kill_cmd: C-c
1112
-
1213
- name: databases
1314
panes:
14-
- cmd: cd tmux-compose && sleep 3 && touch database.lock
15+
- cmd: cd tmux-compose; sleep 3 && touch database.lock
1516
readycheck:
1617
test: test -f database.lock
1718
interval: 3s

0 commit comments

Comments
 (0)