mirror of
https://github.com/nushell/nushell
synced 2025-01-14 22:24:54 +00:00
Merge pull request #885 from jonathandturner/update_path
Allow updating PATH in config
This commit is contained in:
commit
8ba5388438
1 changed files with 37 additions and 0 deletions
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 iter = pipeline.commands.into_iter().peekable();
|
||||||
let mut is_first_command = true;
|
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 {
|
loop {
|
||||||
let item: Option<ClassifiedCommand> = iter.next();
|
let item: Option<ClassifiedCommand> = iter.next();
|
||||||
let next: Option<&ClassifiedCommand> = iter.peek();
|
let next: Option<&ClassifiedCommand> = iter.peek();
|
||||||
|
|
Loading…
Reference in a new issue