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,9 +5,11 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec"
"path" "path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -16,6 +18,7 @@ import (
type Project struct { type Project struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Root string `yaml:"root"` Root string `yaml:"root"`
OnProjectStart []string `yaml:"on_project_start"`
Windows []Window `yaml:"windows"` Windows []Window `yaml:"windows"`
} }
@ -26,6 +29,21 @@ func StartProject(name string) {
os.Exit(1) 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) tmux := CreateTmux(false)
if !sessionExists(name) { if !sessionExists(name) {