@@ -13,11 +13,12 @@ import (
1313)
1414
1515type 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
2324type Window struct {
@@ -38,6 +39,8 @@ type Project struct {
3839 Windows []* Window
3940}
4041
42+ var gRestart bool
43+
4144func 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
134137func (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+
257301func 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}
0 commit comments