Add with-env command (#1717)

This commit is contained in:
Jonathan Turner
2020-05-06 15:56:31 +12:00
committed by GitHub
parent 22e70478a4
commit b37e420c7c
13 changed files with 153 additions and 12 deletions

View File

@ -151,7 +151,7 @@ fn evaluate_reference(name: &hir::Variable, scope: &Scope, tag: Tag) -> Result<V
match name {
hir::Variable::It(_) => Ok(scope.it.value.clone().into_value(tag)),
hir::Variable::Other(name, _) => match name {
x if x == "$nu" => crate::evaluate::variables::nu(tag),
x if x == "$nu" => crate::evaluate::variables::nu(scope, tag),
x if x == "$true" => Ok(Value {
value: UntaggedValue::boolean(true),
tag,

View File

@ -1,15 +1,15 @@
use crate::cli::History;
use nu_errors::ShellError;
use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value};
use nu_protocol::{Scope, TaggedDictBuilder, UntaggedValue, Value};
use nu_source::Tag;
pub fn nu(tag: impl Into<Tag>) -> Result<Value, ShellError> {
pub fn nu(scope: &Scope, tag: impl Into<Tag>) -> Result<Value, ShellError> {
let tag = tag.into();
let mut nu_dict = TaggedDictBuilder::new(&tag);
let mut dict = TaggedDictBuilder::new(&tag);
for v in std::env::vars() {
for v in scope.env.iter() {
if v.0 != "PATH" && v.0 != "Path" {
dict.insert_untagged(v.0, UntaggedValue::string(v.1));
}