29 lines
523 B
Go
Raw Normal View History

2023-08-18 15:01:42 +00:00
package core
import (
"os/exec"
"regexp"
"strings"
)
var (
sh = regexp.MustCompile("\\{([^\\}]+)\\}")
)
func Process(source string) string {
source = sh.ReplaceAllStringFunc(source, func(match string) string {
cmd := sh.FindStringSubmatch(match)[1]
args := strings.Fields(cmd)
shellArgs := []string{"-c", strings.Join(args, " ")}
output, err := exec.Command("sh", shellArgs...).CombinedOutput()
if err != nil {
return err.Error()
}
return strings.Trim(string(output), "\n")
})
return source
}