@@ -29,11 +29,13 @@ type Window struct {
2929}
3030
3131type Project struct {
32- Name string
33- Dir string
34- PreCmd string `yaml:"pre_cmd"`
35- PostCmd string `yaml:"post_cmd"`
36- Windows []* Window
32+ Name string
33+ Dir string
34+ UpPreCmd string `yaml:"up_pre_cmd"`
35+ UpPostCmd string `yaml:"up_post_cmd"`
36+ DownPreCmd string `yaml:"down_pre_cmd"`
37+ DownPostCmd string `yaml:"down_post_cmd"`
38+ Windows []* Window
3739}
3840
3941func run (format string , args ... interface {}) error {
@@ -181,8 +183,8 @@ func shellInDir(dir, cmd string) {
181183}
182184
183185func up (session string , project * Project ) {
184- if project .PreCmd != "" {
185- shellInDir (project .Dir , project .PreCmd )
186+ if project .UpPreCmd != "" {
187+ shellInDir (project .Dir , project .UpPreCmd )
186188 }
187189
188190 // Spawn all the windows/panes
@@ -209,6 +211,17 @@ func up(session string, project *Project) {
209211 SelectLayout (target , w .Layout )
210212 }
211213
214+ // Set which window has focus
215+ for wi , w := range project .Windows {
216+ if w == nil {
217+ continue
218+ }
219+ if w .Focus {
220+ target := fmt .Sprintf ("%s:%d" , session , wi )
221+ SelectWindow (target )
222+ }
223+ }
224+
212225 // Run the commands concurrently
213226 for _ , w := range project .Windows {
214227 if w == nil {
@@ -224,24 +237,21 @@ func up(session string, project *Project) {
224237 }
225238 runAll ()
226239
227- // Set which window has focus
228- for wi , w := range project .Windows {
229- if w == nil {
230- continue
231- }
232- if w .Focus {
233- target := fmt .Sprintf ("%s:%d" , session , wi )
234- SelectWindow (target )
235- }
236- }
237-
238- if project .PostCmd != "" {
239- shellInDir (project .Dir , project .PostCmd )
240+ if project .UpPostCmd != "" {
241+ shellInDir (project .Dir , project .UpPostCmd )
240242 }
241243}
242244
243245func down (session string , project * Project ) {
246+ if project .DownPreCmd != "" {
247+ shellInDir (project .Dir , project .DownPreCmd )
248+ }
249+
244250 KillSession (session )
251+
252+ if project .DownPostCmd != "" {
253+ shellInDir (project .Dir , project .DownPostCmd )
254+ }
245255}
246256
247257func main () {
0 commit comments