func NewWorkRequest(cmd string, dir string, topdir string) *termite.WorkRequest { req := &termite.WorkRequest{ Binary: Shell(), Argv: []string{Shell(), "-c", cmd}, Env: cleanEnv(os.Environ()), Dir: dir, } parsed := termite.ParseCommand(cmd) if len(parsed) > 0 { // Is this really necessary? for _, c := range bashInternals { if parsed[0] == c { return req } } // A no-frills command invocation: do it directly. binary, err := exec.LookPath(parsed[0]) if err == nil { req.Argv = parsed if len(binary) > 0 && binary[0] != '/' { binary = filepath.Join(req.Dir, binary) } req.Binary = binary } } return req }
func TryRunDirect(cmd string) { if cmd == ":" { os.Exit(0) } parsed := termite.ParseCommand(cmd) if len(parsed) == 0 { return } if parsed[0] == "echo" { fmt.Println(strings.Join(parsed[1:], " ")) os.Exit(0) } if parsed[0] == "true" { os.Exit(0) } if parsed[0] == "false" { os.Exit(1) } // TODO mkdir, rm, expr, others? }