2023-08-18 18:52:40 +02:00

31 lines
570 B
Go

package core
import (
"os/exec"
"regexp"
"strings"
"github.com/rivo/tview"
)
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 tview.TranslateANSI(strings.Trim(string(output), "\n"))
})
return source
}