From 30b6eac03dfd9c119b0ee4c95d34f0a1758e2e5d Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Tue, 29 Oct 2019 10:22:31 +1300 Subject: [PATCH] Allow updating path in config --- src/cli.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index d52a55e267..9661cb3202 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -520,6 +520,43 @@ async fn process_line(readline: Result, 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 = iter.next(); let next: Option<&ClassifiedCommand> = iter.peek();