Aliases now take arguments
This commit is contained in:
parent
30cb3f9887
commit
e4101883e1
36
src/lib.rs
36
src/lib.rs
@ -221,14 +221,39 @@ pub mod shell {
|
|||||||
stdout.flush();
|
stdout.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn transform_alias(conf: &SqishConf, full_command: String) -> String {
|
||||||
|
let binding = full_command.clone();
|
||||||
|
let mut pieces = binding.split_whitespace()
|
||||||
|
.collect::<Vec<&str>>();
|
||||||
|
let command_temp = match pieces.first() {
|
||||||
|
Some(c) => c,
|
||||||
|
None => {
|
||||||
|
return full_command;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let command = String::from(*command_temp);
|
||||||
|
|
||||||
|
pieces.remove(0);
|
||||||
|
let arg = match pieces.len() {
|
||||||
|
0 => String::from(""),
|
||||||
|
_ => format!(" {}", pieces.join(" ")),
|
||||||
|
};
|
||||||
|
|
||||||
|
if conf.aliases.contains_key(&command) && command.chars().count() > 0 {
|
||||||
|
let ret_string = format!("{}{}", conf.aliases[&command], arg);
|
||||||
|
return ret_string;
|
||||||
|
} else {
|
||||||
|
return full_command;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn run_cmd(mycommand: &mut String,
|
fn run_cmd(mycommand: &mut String,
|
||||||
current_number: &mut i32,
|
current_number: &mut i32,
|
||||||
conf: &mut SqishConf,
|
conf: &mut SqishConf,
|
||||||
stdout: &mut RawTerminal<Stdout>) {
|
stdout: &mut RawTerminal<Stdout>) {
|
||||||
//Handling aliases
|
|
||||||
if conf.aliases.contains_key(mycommand) {
|
|
||||||
*mycommand = conf.aliases[mycommand].clone();
|
|
||||||
}
|
|
||||||
if (mycommand != &String::from("")) && (mycommand != &String::from("exit")) {
|
if (mycommand != &String::from("")) && (mycommand != &String::from("exit")) {
|
||||||
let comm = replace_signs(&mycommand);
|
let comm = replace_signs(&mycommand);
|
||||||
RawTerminal::suspend_raw_mode(&stdout);
|
RawTerminal::suspend_raw_mode(&stdout);
|
||||||
@ -303,6 +328,7 @@ pub mod shell {
|
|||||||
let mut current_pos: usize = 0;
|
let mut current_pos: usize = 0;
|
||||||
let mut max_pos: usize = 0;
|
let mut max_pos: usize = 0;
|
||||||
|
|
||||||
|
|
||||||
//Handle Ctrl+C
|
//Handle Ctrl+C
|
||||||
ctrlc::set_handler(|| {
|
ctrlc::set_handler(|| {
|
||||||
();
|
();
|
||||||
@ -325,7 +351,6 @@ pub mod shell {
|
|||||||
};
|
};
|
||||||
&conf.update_prompt(get_curr_history_number());
|
&conf.update_prompt(get_curr_history_number());
|
||||||
|
|
||||||
|
|
||||||
//Initialize
|
//Initialize
|
||||||
write!(stdout, "\r\n SquiShell (sqish)--- \r\n{}", conf.promptline);
|
write!(stdout, "\r\n SquiShell (sqish)--- \r\n{}", conf.promptline);
|
||||||
stdout.flush();
|
stdout.flush();
|
||||||
@ -353,6 +378,7 @@ pub mod shell {
|
|||||||
current_number = get_curr_history_number();
|
current_number = get_curr_history_number();
|
||||||
current_pos = 0;
|
current_pos = 0;
|
||||||
max_pos = 0;
|
max_pos = 0;
|
||||||
|
mycommand = transform_alias(&conf, mycommand);
|
||||||
run_cmd(&mut mycommand,
|
run_cmd(&mut mycommand,
|
||||||
&mut current_number,
|
&mut current_number,
|
||||||
&mut conf,
|
&mut conf,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user