Added a dirty implementation of env var setting
This commit is contained in:
parent
1eb1b239c2
commit
68dc23a15e
35
src/lib.rs
35
src/lib.rs
@ -1,5 +1,6 @@
|
|||||||
#[allow(unused_must_use)]
|
#[allow(unused_must_use)]
|
||||||
pub mod shell {
|
pub mod shell {
|
||||||
|
use regex::Regex;
|
||||||
use std::io::Stdout;
|
use std::io::Stdout;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::io::stdin;
|
use std::io::stdin;
|
||||||
@ -412,6 +413,7 @@ pub mod shell {
|
|||||||
aliases: HashMap::new(),
|
aliases: HashMap::new(),
|
||||||
hotkeys: HashMap::new(),
|
hotkeys: HashMap::new(),
|
||||||
init: String::new(),
|
init: String::new(),
|
||||||
|
env: HashMap::new(),
|
||||||
};
|
};
|
||||||
let ret_line = format!("Could not build conf, got {}\
|
let ret_line = format!("Could not build conf, got {}\
|
||||||
\r\nUsing default promptline", e);
|
\r\nUsing default promptline", e);
|
||||||
@ -636,6 +638,38 @@ pub mod shell {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//I smell horrible code in here
|
||||||
|
fn set_envvars(conf: &SqishConf) {
|
||||||
|
let vars = conf.env.clone();
|
||||||
|
let re = Regex::new(r"\$[A-Za-z_]+").unwrap();
|
||||||
|
|
||||||
|
for (key, value) in vars {
|
||||||
|
let mut after = value.clone();
|
||||||
|
let mut nbr_of_vars = *&value.matches('$').count();
|
||||||
|
while nbr_of_vars >= 1 {
|
||||||
|
let temp = after.clone();
|
||||||
|
let caps = re.captures(&temp).unwrap();
|
||||||
|
for cap in caps.iter() {
|
||||||
|
match cap {
|
||||||
|
Some(c) => {
|
||||||
|
let myvar = String::from(c.as_str()).replace('$', "");
|
||||||
|
match env::var(myvar) {
|
||||||
|
Ok(r) => {
|
||||||
|
*&mut after = after.replace(c.as_str(), &r);
|
||||||
|
},
|
||||||
|
Err(_) => continue,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
nbr_of_vars -= 1;
|
||||||
|
}
|
||||||
|
env::set_var(&key, &after);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//THE ENTRYPOINT FUNCTION
|
//THE ENTRYPOINT FUNCTION
|
||||||
pub fn run_raw() {
|
pub fn run_raw() {
|
||||||
|
|
||||||
@ -658,6 +692,7 @@ pub mod shell {
|
|||||||
//Initializing
|
//Initializing
|
||||||
write!(elems.stdout, "\r\n ---Sqish initializing--- \r\n{}", elems.conf.promptline);
|
write!(elems.stdout, "\r\n ---Sqish initializing--- \r\n{}", elems.conf.promptline);
|
||||||
elems.stdout.flush();
|
elems.stdout.flush();
|
||||||
|
set_envvars(&elems.conf);
|
||||||
|
|
||||||
if elems.conf.init != String::from("") {
|
if elems.conf.init != String::from("") {
|
||||||
run_cmd(&mut String::from(&elems.conf.init), &mut elems.current_number, &mut elems.conf, &mut elems.stdout);
|
run_cmd(&mut String::from(&elems.conf.init), &mut elems.current_number, &mut elems.conf, &mut elems.stdout);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user