From 96e52579a46797c42d5dfab5698011f512a0851c Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Sat, 13 Feb 2016 21:24:46 +0100 Subject: [PATCH] Add an "-exec" builtin. --- eval/builtin_func.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/eval/builtin_func.go b/eval/builtin_func.go index 3861de4d..9eab1b07 100644 --- a/eval/builtin_func.go +++ b/eval/builtin_func.go @@ -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) +}