mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
Add an "-exec" builtin.
This commit is contained in:
parent
e3826f42ae
commit
96e52579a4
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user