|
|
@ -5,7 +5,9 @@ use std::env; |
|
|
|
|
|
|
|
const ENV_SET: Lazy<Regex> = Lazy::new(|| Regex::new(r#"(?P<key>\w+)=(?P<value>\w*)"#).unwrap());
|
|
|
|
|
|
|
|
pub fn preprocess(line: String) -> Result<String, ShellError> {
|
|
|
|
/// 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<Option<String>, 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<String, ShellError> { |
|
|
|
.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))
|
|
|
|
}
|