mirror of
https://github.com/nushell/nushell.git
synced 2024-12-27 09:29:14 +01:00
Merge pull request #885 from jonathandturner/update_path
Allow updating PATH in config
This commit is contained in:
commit
8ba5388438
37
src/cli.rs
37
src/cli.rs
@ -520,6 +520,43 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
|
||||
let mut iter = pipeline.commands.into_iter().peekable();
|
||||
let mut is_first_command = true;
|
||||
|
||||
// Check the config to see if we need to update the path
|
||||
// TODO: make sure config is cached so we don't path this load every call
|
||||
let config = crate::data::config::read(Tag::unknown(), &None).unwrap();
|
||||
if config.contains_key("path") {
|
||||
// Override the path with what they give us from config
|
||||
let value = config.get("path");
|
||||
|
||||
match value {
|
||||
Some(value) => match value {
|
||||
Tagged {
|
||||
item: Value::Table(table),
|
||||
..
|
||||
} => {
|
||||
let mut paths = vec![];
|
||||
for val in table {
|
||||
let path_str = val.as_string();
|
||||
match path_str {
|
||||
Err(_) => {}
|
||||
Ok(path_str) => {
|
||||
paths.push(PathBuf::from(path_str));
|
||||
}
|
||||
}
|
||||
}
|
||||
let path_os_string = std::env::join_paths(&paths);
|
||||
match path_os_string {
|
||||
Ok(path_os_string) => {
|
||||
std::env::set_var("PATH", path_os_string);
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
loop {
|
||||
let item: Option<ClassifiedCommand> = iter.next();
|
||||
let next: Option<&ClassifiedCommand> = iter.peek();
|
||||
|
Loading…
Reference in New Issue
Block a user