Now handling double quotes properly
This commit is contained in:
parent
6f63294857
commit
d22e34c8bd
@ -17,3 +17,4 @@ which = { version = "4.4.0", features = ["regex"] }
|
||||
regex = "1.7.1"
|
||||
yaml-rust = "0.4.5"
|
||||
ctrlc = "3.2.5"
|
||||
shell-words = "1.1.0"
|
||||
|
26
src/lib.rs
26
src/lib.rs
@ -30,24 +30,22 @@ pub mod shell {
|
||||
|
||||
//used for home directory
|
||||
extern crate dirs;
|
||||
|
||||
extern crate shell_words;
|
||||
extern crate ctrlc;
|
||||
|
||||
|
||||
|
||||
fn process_line(input: &str) -> String {
|
||||
fn process_line(input: &str) -> Result<String, shell_words::ParseError> {
|
||||
let mut commands = input.trim().split("|").peekable();
|
||||
let mut previous_command = None;
|
||||
let mut resultat = String::new();
|
||||
|
||||
while let Some(command) = commands.next() {
|
||||
let mut parts = command.trim().split_whitespace();
|
||||
let command = parts.next().unwrap();
|
||||
let args = parts;
|
||||
let parts = shell_words::split(&command.trim())?;
|
||||
let command = parts[0].as_str();
|
||||
let args = Vec::from(&parts[1..]);
|
||||
|
||||
match command {
|
||||
"cd" => {
|
||||
let args = args.collect::<Vec<&str>>();
|
||||
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 mut new_dir = String::new();
|
||||
@ -116,7 +114,7 @@ pub mod shell {
|
||||
Ok(h) => h,
|
||||
Err(_) => {
|
||||
let err_string = format!("Not found : {}", command);
|
||||
return String::from(err_string);
|
||||
return Ok(String::from(err_string));
|
||||
},
|
||||
};
|
||||
|
||||
@ -135,7 +133,7 @@ pub mod shell {
|
||||
},
|
||||
};
|
||||
}
|
||||
return resultat;
|
||||
return Ok(resultat);
|
||||
}
|
||||
|
||||
fn replace_signs(line: &String) -> String {
|
||||
@ -162,7 +160,7 @@ pub mod shell {
|
||||
match command_found {
|
||||
Some(c) => {
|
||||
write_to_history(&c);
|
||||
let outp = process_line(&c);
|
||||
let outp = process_line(&c).unwrap();
|
||||
return outp;
|
||||
},
|
||||
None => return String::from(" "),
|
||||
@ -170,7 +168,7 @@ pub mod shell {
|
||||
//Regular command
|
||||
} else if line.len() > 0 {
|
||||
write_to_history(line);
|
||||
return process_line(line);
|
||||
return process_line(line).unwrap();
|
||||
//Nothing
|
||||
} else {
|
||||
//Command was empty, new line
|
||||
@ -374,7 +372,7 @@ pub mod shell {
|
||||
&conf.update_prompt(get_curr_history_number());
|
||||
|
||||
//Initializing
|
||||
write!(stdout, "\r\n ---Sqish initializing...--- \r\n{}", conf.promptline);
|
||||
write!(stdout, "\r\n ---Sqish initializing--- \r\n{}", conf.promptline);
|
||||
stdout.flush();
|
||||
|
||||
if conf.init != String::from("") {
|
||||
@ -593,8 +591,10 @@ pub mod shell {
|
||||
append_prev_arg(&mut mycommand, &mut current_pos, &mut max_pos);
|
||||
},
|
||||
'!' => {
|
||||
let mut cmd = format!("\r\n-- ALIASES --> \r\n{:?}\r\n", conf.hotkeys);
|
||||
let mut cmd = format!("\r\n-- HOTKEYS --> \r\n{:?}\r\n", conf.hotkeys);
|
||||
cmd = format!("{}\r\n-- ALIASES -->\r\n{:?}\r\n", cmd, conf.aliases);
|
||||
cmd = cmd.replace(",", "\r\n");
|
||||
cmd = cmd.replace('"', "");
|
||||
write!(stdout, "{}", cmd);
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user