github.com/elves/elvish@v0.15.0/pkg/eval/builtin_ns.go (about)

     1  package eval
     2  
     3  import (
     4  	"strconv"
     5  	"syscall"
     6  
     7  	"github.com/elves/elvish/pkg/eval/vars"
     8  )
     9  
    10  //elvdoc:var _
    11  //
    12  // A blackhole variable.
    13  //
    14  // Values assigned to it will be discarded. Referencing it always results in $nil.
    15  
    16  //elvdoc:var args
    17  //
    18  // A list containing command-line arguments. Analogous to `argv` in some other
    19  // languages. Examples:
    20  //
    21  // ```elvish-transcript
    22  // ~> echo 'put $args' > args.elv
    23  // ~> elvish args.elv foo -bar
    24  // ▶ [foo -bar]
    25  // ~> elvish -c 'put $args' foo -bar
    26  // ▶ [foo -bar]
    27  // ```
    28  //
    29  // As demonstrated above, this variable does not contain the name of the script
    30  // used to invoke it. For that information, use the `src` command.
    31  //
    32  // @cf src
    33  
    34  //elvdoc:var false
    35  //
    36  // The boolean false value.
    37  
    38  //elvdoc:var ok
    39  //
    40  // The special value used by `?()` to signal absence of exceptions.
    41  
    42  //elvdoc:var nil
    43  //
    44  // A special value useful for representing the lack of values.
    45  
    46  //elvdoc:var paths
    47  //
    48  // A list of search paths, kept in sync with `$E:PATH`. It is easier to use than
    49  // `$E:PATH`.
    50  
    51  //elvdoc:var pid
    52  //
    53  // The process ID of the current Elvish process.
    54  
    55  //elvdoc:var pwd
    56  //
    57  // The present working directory. Setting this variable has the same effect as
    58  // `cd`. This variable is most useful in a temporary assignment.
    59  //
    60  // Example:
    61  //
    62  // ```elvish
    63  // ## Updates all git repositories
    64  // for x [*/] {
    65  //   pwd=$x {
    66  //     if ?(test -d .git) {
    67  //       git pull
    68  //     }
    69  //   }
    70  // }
    71  // ```
    72  //
    73  // Etymology: the `pwd` command.
    74  //
    75  // @cf cd
    76  
    77  //elvdoc:var true
    78  //
    79  // The boolean true value.
    80  
    81  var builtinNs = NsBuilder{
    82  	"_":     vars.NewBlackhole(),
    83  	"pid":   vars.NewReadOnly(strconv.Itoa(syscall.Getpid())),
    84  	"ok":    vars.NewReadOnly(OK),
    85  	"nil":   vars.NewReadOnly(nil),
    86  	"true":  vars.NewReadOnly(true),
    87  	"false": vars.NewReadOnly(false),
    88  	"paths": vars.NewEnvListVar("PATH"),
    89  }
    90  
    91  func addBuiltinFns(fns map[string]interface{}) {
    92  	builtinNs.AddGoFns("", fns)
    93  }