Add an "-exec" builtin.

This commit is contained in:
Qi Xiao 2016-02-13 21:24:46 +01:00
parent e3826f42ae
commit 96e52579a4

View File

@ -12,6 +12,7 @@ import (
"reflect"
"runtime"
"strconv"
"syscall"
"time"
"github.com/elves/elvish/logutil"
@ -69,6 +70,7 @@ func init() {
&BuiltinFn{"-sleep", wrapFn(_sleep)},
&BuiltinFn{"-stack", wrapFn(_stack)},
&BuiltinFn{"-log", wrapFn(_log)},
&BuiltinFn{"-exec", wrapFn(_exec)},
}
}
@ -520,3 +522,14 @@ func _stack(ec *EvalCtx) {
func _log(ec *EvalCtx, fname string) {
maybeThrow(logutil.SetOutputFile(fname))
}
func _exec(ec *EvalCtx, args ...string) {
if len(args) == 0 {
args = []string{"elvish"}
}
var err error
args[0], err = ec.Search(args[0])
maybeThrow(err)
err = syscall.Exec(args[0], args, os.Environ())
maybeThrow(err)
}