mirror of
https://github.com/nushell/nushell.git
synced 2025-03-15 07:58:31 +01:00
Merge pull request #883 from jonathandturner/magic_env_vars
Add support for $nu:config and $nu:env
This commit is contained in:
commit
bc309705a9
@ -5,6 +5,7 @@ use crate::parser::{
|
|||||||
CommandRegistry, Text,
|
CommandRegistry, Text,
|
||||||
};
|
};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use crate::TaggedDictBuilder;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
@ -164,11 +165,24 @@ fn evaluate_reference(
|
|||||||
trace!("Evaluating {} with Scope {}", name, scope);
|
trace!("Evaluating {} with Scope {}", name, scope);
|
||||||
match name {
|
match name {
|
||||||
hir::Variable::It(_) => Ok(scope.it.item.clone().tagged(tag)),
|
hir::Variable::It(_) => Ok(scope.it.item.clone().tagged(tag)),
|
||||||
hir::Variable::Other(inner) => Ok(scope
|
hir::Variable::Other(inner) => match inner.slice(source) {
|
||||||
.vars
|
x if x == "nu:env" => {
|
||||||
.get(inner.slice(source))
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
.map(|v| v.clone())
|
for v in std::env::vars() {
|
||||||
.unwrap_or_else(|| Value::nothing().tagged(tag))),
|
dict.insert(v.0, Value::string(v.1));
|
||||||
|
}
|
||||||
|
Ok(dict.into_tagged_value())
|
||||||
|
}
|
||||||
|
x if x == "nu:config" => {
|
||||||
|
let config = crate::data::config::read(tag.clone(), &None)?;
|
||||||
|
Ok(Value::row(config).tagged(tag))
|
||||||
|
}
|
||||||
|
x => Ok(scope
|
||||||
|
.vars
|
||||||
|
.get(x)
|
||||||
|
.map(|v| v.clone())
|
||||||
|
.unwrap_or_else(|| Value::nothing().tagged(tag))),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user