diff --git a/src/execute.rs b/src/execute.rs index a8b637a..d3614db 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -13,7 +13,11 @@ pub fn interpret( config: &mut BuiltinConfig, ctrlc_recv: Receiver<()>, ) -> Result<(), ShellError> { - line = preprocess(line)?; + if let Some(l) = preprocess(line)? { + line = l + } else { + return Ok(()); + } if line.is_empty() { return Err(ShellError::EmptyLine); diff --git a/src/preprocess.rs b/src/preprocess.rs index 6541726..f802b9c 100644 --- a/src/preprocess.rs +++ b/src/preprocess.rs @@ -5,7 +5,9 @@ use std::env; const ENV_SET: Lazy = Lazy::new(|| Regex::new(r#"(?P\w+)=(?P\w*)"#).unwrap()); -pub fn preprocess(line: String) -> Result { +/// Returns `Ok(Some(...))` if a command should be triggered after calling this functions. If it +/// returns `Ok(None)`, do not execute a command. +pub fn preprocess(line: String) -> Result, ShellError> { if let Some(capture) = ENV_SET.captures(&line) { let Some(key) = capture.name("key") else { return Err(ShellError::MalformedArgs("cannot find key to set env variable".to_string())) @@ -14,8 +16,9 @@ pub fn preprocess(line: String) -> Result { .name("value") .map_or("".to_string(), |v| v.as_str().to_string()); - env::set_var(key.as_str(), value) + env::set_var(key.as_str(), value); + return Ok(None); } - Ok(line) + Ok(Some(line)) }