Keep the environment properly set. (#3072)

* Revert "fix prompts on startup (#3056)"

This reverts commit b202951c1d.

* Ensure environment variables synced with global internal Nu Scope.
This commit is contained in:
Andrés N. Robalino
2021-02-17 21:56:14 -05:00
committed by GitHub
parent 892aae267d
commit 08e7d0dfb6
6 changed files with 233 additions and 53 deletions

View File

@ -176,8 +176,7 @@ impl Scope {
pub fn add_env_var(&self, name: impl Into<String>, value: String) {
if let Some(frame) = self.frames.lock().last_mut() {
let name = name.into();
frame.env.insert(name, value);
frame.env.insert(name.into(), value);
}
}
@ -192,6 +191,12 @@ impl Scope {
frame.env.extend(env_vars)
}
}
pub fn add_env_var_to_base(&self, name: impl Into<String>, value: String) {
if let Some(frame) = self.frames.lock().first_mut() {
frame.env.insert(name.into(), value);
}
}
}
impl ParserScope for Scope {

View File

@ -21,10 +21,11 @@ pub fn nu(env: &IndexMap<String, String>, tag: impl Into<Tag>) -> Result<Value,
nu_dict.insert_value("config", UntaggedValue::row(config).into_value(&tag));
let mut table = vec![];
let path = std::env::var_os("PATH");
if let Some(paths) = path {
for path in std::env::split_paths(&paths) {
table.push(UntaggedValue::filepath(path).into_value(&tag));
for v in env.iter() {
if v.0 == "PATH" || v.0 == "Path" {
for path in std::env::split_paths(&v.1) {
table.push(UntaggedValue::filepath(path).into_value(&tag));
}
}
}
nu_dict.insert_value("path", UntaggedValue::table(&table).into_value(&tag));