Compare commits
No commits in common. "1eefd44a89514b1a1554a63154355ec3bb15218e" and "1e052f1a79bdd4754cd8f769367b594f23d6fb38" have entirely different histories.
1eefd44a89
...
1e052f1a79
@ -18,9 +18,14 @@ Also keep in mind I'm a beginner in Rust, so the code is pretty dirty; I will pr
|
|||||||
|
|
||||||
TODO (Reformat):
|
TODO (Reformat):
|
||||||
* Creating a struct "shell" that contains builder method taking an input and an output as parameters as well as a conf could be cool
|
* Creating a struct "shell" that contains builder method taking an input and an output as parameters as well as a conf could be cool
|
||||||
|
* Maybe subdivide lib.src to have more modularity 'cause it getting kinda long... 500 lines it a bit much ?
|
||||||
|
|
||||||
TODO (features):
|
TODO(Features):
|
||||||
* Add a &&
|
* Allow redirecting >> to the end of a file ?
|
||||||
|
* Allow && in commands ?
|
||||||
|
* Improve word jumping
|
||||||
|
* Add arguments : run a file (sqish myexec) which I believe would make it compatible with gdb ?
|
||||||
|
* Add export command => Reuse the function set_envvars
|
||||||
|
|
||||||
## sqishrc (Config)
|
## sqishrc (Config)
|
||||||
See the included sqishrc file included for comments, and copy it as ~/.sqishrc for use (optionnal).
|
See the included sqishrc file included for comments, and copy it as ~/.sqishrc for use (optionnal).
|
||||||
|
29
src/lib.rs
29
src/lib.rs
@ -73,21 +73,6 @@ pub mod shell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn export_var(command: String) -> Result<CmdOutput, CmdOutput> {
|
|
||||||
let cmd_split = command.split('=').collect::<Vec<&str>>();
|
|
||||||
if cmd_split.len() < 2 {
|
|
||||||
return Err(CmdOutput::from_values(
|
|
||||||
String::from("Please a format such as : VAR=value"),
|
|
||||||
255));
|
|
||||||
}
|
|
||||||
let key = String::from(cmd_split[0].to_uppercase());
|
|
||||||
let val = String::from(cmd_split[1]);
|
|
||||||
let mut map = HashMap::new();
|
|
||||||
map.insert(key, val);
|
|
||||||
set_envvars(&map);
|
|
||||||
return Ok(CmdOutput::new_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn change_dir(args: &Vec<String>, previous_command: &mut Option<Stdio>) -> Result<CmdOutput, CmdOutput> {
|
fn change_dir(args: &Vec<String>, previous_command: &mut Option<Stdio>) -> Result<CmdOutput, CmdOutput> {
|
||||||
let homedir = dirs::home_dir().unwrap().into_os_string().into_string().unwrap();
|
let homedir = dirs::home_dir().unwrap().into_os_string().into_string().unwrap();
|
||||||
//let new_dir = args.peekable().peek().map_or(homedir.as_str(), |x| *x);
|
//let new_dir = args.peekable().peek().map_or(homedir.as_str(), |x| *x);
|
||||||
@ -142,25 +127,17 @@ pub mod shell {
|
|||||||
return Err(CmdOutput::from_values(format!("Could not parse command {:?}", e), -1));
|
return Err(CmdOutput::from_values(format!("Could not parse command {:?}", e), -1));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if parts.len() < 1 {
|
|
||||||
return Err(CmdOutput::from_values(String::from("Could not parse command"), -1));
|
|
||||||
}
|
|
||||||
let command = parts[0].as_str();
|
let command = parts[0].as_str();
|
||||||
let args = Vec::from(&parts[1..]);
|
let args = Vec::from(&parts[1..]);
|
||||||
|
|
||||||
match command {
|
match command {
|
||||||
"cd" => {
|
"cd" => {
|
||||||
change_dir(&args, &mut previous_command)?;
|
change_dir(&args, &mut previous_command)?;
|
||||||
print!("\r\n");
|
|
||||||
},
|
},
|
||||||
"history" => {
|
"history" => {
|
||||||
let next = commands.peek().is_some();
|
let next = commands.peek().is_some();
|
||||||
print_hist(&mut previous_command, next)?;
|
print_hist(&mut previous_command, next)?;
|
||||||
},
|
},
|
||||||
"export" => {
|
|
||||||
export_var(args.join(" "))?;
|
|
||||||
print!("\r\n");
|
|
||||||
},
|
|
||||||
command => {
|
command => {
|
||||||
if commands.peek().is_some() {
|
if commands.peek().is_some() {
|
||||||
let stdin = match previous_command {
|
let stdin = match previous_command {
|
||||||
@ -662,8 +639,8 @@ pub mod shell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//I smell horrible code in here
|
//I smell horrible code in here
|
||||||
fn set_envvars(vars: &HashMap<String, String>) {
|
fn set_envvars(conf: &SqishConf) {
|
||||||
let vars = vars.clone();
|
let vars = conf.env.clone();
|
||||||
let re = Regex::new(r"\$[A-Za-z_]+").unwrap();
|
let re = Regex::new(r"\$[A-Za-z_]+").unwrap();
|
||||||
|
|
||||||
for (key, value) in vars {
|
for (key, value) in vars {
|
||||||
@ -715,7 +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.env);
|
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