31 lines
570 B
Go
Raw Permalink Normal View History

2023-08-18 15:01:42 +00:00
package core
import (
"os/exec"
"regexp"
"strings"
2023-08-18 16:52:40 +00:00
"github.com/rivo/tview"
2023-08-18 15:01:42 +00:00
)
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()
}
2023-08-18 16:52:40 +00:00
return tview.TranslateANSI(strings.Trim(string(output), "\n"))
2023-08-18 15:01:42 +00:00
})
return source
}