2016-02-28 06:43:54 +08:00
|
|
|
package eval
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"syscall"
|
2018-01-01 23:21:15 +08:00
|
|
|
|
2021-06-17 12:39:16 +08:00
|
|
|
"src.elv.sh/pkg/buildinfo"
|
2021-01-27 09:28:38 +08:00
|
|
|
"src.elv.sh/pkg/eval/vars"
|
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.
|
|
|
|
|
2021-06-17 12:39:16 +08:00
|
|
|
//elvdoc:var buildinfo
|
|
|
|
//
|
|
|
|
// A [psuedo-map](./language.html#pseudo-map) that exposes information about the Elvish binary.
|
|
|
|
// Running `put $buildinfo | to-json` will produce the same output as `elvish -buildinfo -json`.
|
|
|
|
//
|
|
|
|
// @cf version
|
|
|
|
|
|
|
|
//elvdoc:var version
|
|
|
|
//
|
|
|
|
// The full version of the Elvish binary as a string. This is the same information reported by
|
|
|
|
// `elvish -version` and the value of `$buildinfo[version]`.
|
|
|
|
//
|
|
|
|
// **Note:** In general it is better to perform functionality tests rather than testing `$version`.
|
|
|
|
// For example, do something like
|
|
|
|
//
|
|
|
|
// ```
|
|
|
|
// has-key $builtin: new-var
|
|
|
|
// ````
|
|
|
|
//
|
|
|
|
// to test if variable `new-var` is available rather than comparing against `$version` to see if the
|
|
|
|
// elvish version is equal to or newer than the version that introduced `new-var`.
|
|
|
|
//
|
|
|
|
// @cf buildinfo
|
|
|
|
|
2021-10-24 04:44:11 +08:00
|
|
|
var builtinNs = BuildNsNamed("").AddVars(map[string]vars.Var{
|
2021-06-17 12:39:16 +08:00
|
|
|
"_": vars.NewBlackhole(),
|
|
|
|
"pid": vars.NewReadOnly(strconv.Itoa(syscall.Getpid())),
|
|
|
|
"ok": vars.NewReadOnly(OK),
|
|
|
|
"nil": vars.NewReadOnly(nil),
|
|
|
|
"true": vars.NewReadOnly(true),
|
|
|
|
"false": vars.NewReadOnly(false),
|
2021-07-04 03:34:56 +08:00
|
|
|
"buildinfo": vars.NewReadOnly(buildinfo.Value),
|
|
|
|
"version": vars.NewReadOnly(buildinfo.Value.Version),
|
2021-06-17 12:39:16 +08:00
|
|
|
"paths": vars.NewEnvListVar("PATH"),
|
2021-10-24 04:44:11 +08:00
|
|
|
})
|
2017-06-28 07:39:05 +08:00
|
|
|
|
2022-03-20 23:50:25 +08:00
|
|
|
func addBuiltinFns(fns map[string]any) {
|
2021-10-24 04:44:11 +08:00
|
|
|
builtinNs.AddGoFns(fns)
|
2018-02-04 12:25:23 +08:00
|
|
|
}
|