2016-02-28 06:43:54 +08:00
|
|
|
package eval
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"syscall"
|
2018-01-01 23:21:15 +08:00
|
|
|
|
2019-12-24 04:00:59 +08:00
|
|
|
"github.com/elves/elvish/pkg/eval/vars"
|
2018-09-29 03:08:32 +08:00
|
|
|
"github.com/xiaq/persistent/vector"
|
2016-02-28 06:43:54 +08:00
|
|
|
)
|
|
|
|
|
2020-01-18 21:12:50 +08:00
|
|
|
//elvdoc:var _
|
|
|
|
//
|
|
|
|
// A blackhole variable.
|
|
|
|
//
|
2020-09-05 05:45:04 +08:00
|
|
|
// Values assigned to it will be discarded. Referencing it always results in $nil.
|
2020-01-18 21:12:50 +08:00
|
|
|
|
|
|
|
//elvdoc:var args
|
|
|
|
//
|
|
|
|
// A list containing command-line arguments. Analogous to `argv` in some other
|
|
|
|
// languages. Examples:
|
|
|
|
//
|
|
|
|
// ```elvish-transcript
|
|
|
|
// ~> echo 'put $args' > args.elv
|
|
|
|
// ~> elvish args.elv foo -bar
|
|
|
|
// ▶ [foo -bar]
|
|
|
|
// ~> elvish -c 'put $args' foo -bar
|
|
|
|
// ▶ [foo -bar]
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// As demonstrated above, this variable does not contain the name of the script
|
|
|
|
// used to invoke it. For that information, use the `src` command.
|
|
|
|
//
|
|
|
|
// @cf src
|
|
|
|
|
|
|
|
//elvdoc:var false
|
|
|
|
//
|
|
|
|
// The boolean false value.
|
|
|
|
|
|
|
|
//elvdoc:var ok
|
|
|
|
//
|
|
|
|
// The special value used by `?()` to signal absence of exceptions.
|
|
|
|
|
|
|
|
//elvdoc:var nil
|
|
|
|
//
|
|
|
|
// A special value useful for representing the lack of values.
|
|
|
|
|
|
|
|
//elvdoc:var paths
|
|
|
|
//
|
|
|
|
// A list of search paths, kept in sync with `$E:PATH`. It is easier to use than
|
|
|
|
// `$E:PATH`.
|
|
|
|
|
|
|
|
//elvdoc:var pid
|
|
|
|
//
|
|
|
|
// The process ID of the current Elvish process.
|
|
|
|
|
|
|
|
//elvdoc:var pwd
|
|
|
|
//
|
|
|
|
// The present working directory. Setting this variable has the same effect as
|
2020-08-17 03:18:20 +08:00
|
|
|
// `cd`. This variable is most useful in a temporary assignment.
|
2020-01-18 21:12:50 +08:00
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// ```elvish
|
|
|
|
// ## Updates all git repositories
|
|
|
|
// for x [*/] {
|
2020-08-17 03:18:20 +08:00
|
|
|
// pwd=$x {
|
|
|
|
// if ?(test -d .git) {
|
|
|
|
// git pull
|
|
|
|
// }
|
|
|
|
// }
|
2020-01-18 21:12:50 +08:00
|
|
|
// }
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// Etymology: the `pwd` command.
|
2020-08-17 03:18:20 +08:00
|
|
|
//
|
|
|
|
// @cf cd
|
2020-01-18 21:12:50 +08:00
|
|
|
|
|
|
|
//elvdoc:var true
|
|
|
|
//
|
|
|
|
// The boolean true value.
|
|
|
|
|
2018-02-07 03:39:40 +08:00
|
|
|
var builtinNs = Ns{
|
2018-02-15 16:59:49 +08:00
|
|
|
"_": vars.NewBlackhole(),
|
2018-11-18 22:23:31 +08:00
|
|
|
"pid": vars.NewReadOnly(strconv.Itoa(syscall.Getpid())),
|
|
|
|
"ok": vars.NewReadOnly(OK),
|
2019-04-08 05:49:28 +08:00
|
|
|
"nil": vars.NewReadOnly(nil),
|
2018-11-18 22:23:31 +08:00
|
|
|
"true": vars.NewReadOnly(true),
|
|
|
|
"false": vars.NewReadOnly(false),
|
2020-09-05 05:24:08 +08:00
|
|
|
"paths": NewEnvListVar("PATH"),
|
2018-11-18 22:23:31 +08:00
|
|
|
"args": vars.NewReadOnly(vector.Empty),
|
2016-02-28 06:43:54 +08:00
|
|
|
}
|
2017-06-28 07:39:05 +08:00
|
|
|
|
2018-02-07 03:39:40 +08:00
|
|
|
func addBuiltinFns(fns map[string]interface{}) {
|
2019-04-19 05:57:14 +08:00
|
|
|
builtinNs.AddGoFns("", fns)
|
2018-02-04 12:25:23 +08:00
|
|
|
}
|