support on_project_start

This commit is contained in:
James Walker 2020-04-19 22:39:12 -04:00
parent 84f1f289ca
commit 724f18395b
Signed by: walkah
GPG Key ID: 3C127179D6086E93

View File

@ -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) {