mirror of
https://github.com/nushell/nushell.git
synced 2025-01-08 07:20:23 +01:00
Reworking adding of vars
This commit is contained in:
parent
688df20a30
commit
dbfd0979a6
@ -1,5 +1,4 @@
|
|||||||
use indexmap::{IndexMap, IndexSet};
|
use indexmap::{IndexMap, IndexSet};
|
||||||
use nu_errors::ShellError;
|
|
||||||
use nu_protocol::{Primitive, UntaggedValue, Value};
|
use nu_protocol::{Primitive, UntaggedValue, Value};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::{
|
use std::{
|
||||||
@ -90,6 +89,7 @@ impl DirectorySpecificEnvironment {
|
|||||||
|
|
||||||
// //WE CRASHING SOMEWHERE HERE
|
// //WE CRASHING SOMEWHERE HERE
|
||||||
|
|
||||||
|
let mut seen_vars = IndexSet::new();
|
||||||
//Start in the current directory, then traverse towards the root with working_dir to see if we are in a subdirectory of a valid directory.
|
//Start in the current directory, then traverse towards the root with working_dir to see if we are in a subdirectory of a valid directory.
|
||||||
while let Some(wdir) = working_dir {
|
while let Some(wdir) = working_dir {
|
||||||
if self.allowed_directories.contains(wdir) {
|
if self.allowed_directories.contains(wdir) {
|
||||||
@ -107,23 +107,28 @@ impl DirectorySpecificEnvironment {
|
|||||||
|
|
||||||
//If we are about to overwrite any environment variables, we save them first so they can be restored later.
|
//If we are about to overwrite any environment variables, we save them first so they can be restored later.
|
||||||
if let Some(existing_val) = std::env::var_os(dir_env_key) {
|
if let Some(existing_val) = std::env::var_os(dir_env_key) {
|
||||||
// if existing_val != dir_env_val {
|
if existing_val == dir_env_val {
|
||||||
// self.overwritten_env_vars
|
seen_vars.insert(dir_env_key.clone());
|
||||||
// .entry(wdir.to_path_buf())
|
} else if !seen_vars.contains(dir_env_key) {
|
||||||
// .or_insert(IndexMap::new())
|
// self.overwritten_env_vars
|
||||||
// .insert(dir_env_key.clone(), existing_val);
|
// .entry(wdir.to_path_buf())
|
||||||
|
// .or_insert(IndexMap::new())
|
||||||
|
// .insert(dir_env_key.clone(), existing_val);
|
||||||
|
|
||||||
// vars_to_add.insert(dir_env_key.clone(), dir_env_val);
|
std::env::set_var(dir_env_key, dir_env_val.clone());
|
||||||
// }
|
seen_vars.insert(dir_env_key.clone());
|
||||||
} else {
|
vars_to_add.insert(dir_env_key.clone(), dir_env_val);
|
||||||
//Otherwise, we just track that we added it here
|
}
|
||||||
self.added_env_vars
|
}// else {
|
||||||
.entry(wdir.to_path_buf())
|
// //Otherwise, we just track that we added it here
|
||||||
.or_insert(IndexSet::new())
|
// // self.added_env_vars
|
||||||
.insert(dir_env_key.clone());
|
// // .entry(wdir.to_path_buf())
|
||||||
|
// // .or_insert(IndexSet::new())
|
||||||
vars_to_add.insert(dir_env_key.clone(), dir_env_val);
|
// // .insert(dir_env_key.clone());
|
||||||
}
|
// std::env::set_var(dir_env_key, dir_env_val.clone());
|
||||||
|
// vars_to_add.insert(dir_env_key.clone(), dir_env_val);
|
||||||
|
// seen_vars.insert(dir_env_key);
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
crates/nu-cli/src/env/environment.rs
vendored
2
crates/nu-cli/src/env/environment.rs
vendored
@ -5,7 +5,6 @@ use indexmap::{indexmap, IndexSet};
|
|||||||
use nu_protocol::{UntaggedValue, Value};
|
use nu_protocol::{UntaggedValue, Value};
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::{fs::OpenOptions, fmt::Debug};
|
use std::{fs::OpenOptions, fmt::Debug};
|
||||||
use nu_errors::ShellError;
|
|
||||||
|
|
||||||
pub trait Env: Debug + Send {
|
pub trait Env: Debug + Send {
|
||||||
fn env(&self) -> Option<Value>;
|
fn env(&self) -> Option<Value>;
|
||||||
@ -76,7 +75,6 @@ impl Environment {
|
|||||||
// std::env::set_var(k, v);
|
// std::env::set_var(k, v);
|
||||||
self.add_env(&k, &v.to_string_lossy(), true);
|
self.add_env(&k, &v.to_string_lossy(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user