diff --git a/tmux/project.go b/tmux/project.go index 235e790..15c79f4 100644 --- a/tmux/project.go +++ b/tmux/project.go @@ -5,18 +5,21 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" "path" "path/filepath" "regexp" + "strings" "github.com/mitchellh/go-homedir" "gopkg.in/yaml.v2" ) type Project struct { - Name string `yaml:"name"` - Root string `yaml:"root"` - Windows []Window `yaml:"windows"` + Name string `yaml:"name"` + Root string `yaml:"root"` + OnProjectStart []string `yaml:"on_project_start"` + Windows []Window `yaml:"windows"` } func StartProject(name string) { @@ -26,6 +29,21 @@ func StartProject(name string) { os.Exit(1) } + // Run startup commands + if len(p.OnProjectStart) > 0 { + for _, command := range p.OnProjectStart { + args := strings.Fields(command) + cmd := exec.Command(args[0], args[1:]...) + cmd.Dir = p.GetRoot() + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Println("Unable to run start command:", err, output) + os.Exit(1) + } + fmt.Println(string(output)) + } + } + tmux := CreateTmux(false) if !sessionExists(name) {