Compare commits
No commits in common. "6fa2788161b167237514dfbdd5d366cd0707fdb8" and "30cb3f9887682a482980ee3a0f6a4c06be7ed323" have entirely different histories.
6fa2788161
...
30cb3f9887
@ -2,6 +2,7 @@
|
|||||||
Rust Shell. This is an attempt to create a simple shell in Rust, because why not.
|
Rust Shell. This is an attempt to create a simple shell in Rust, because why not.
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
* Aliases don't currently handle arguments. My alias "vless" does not work with "vless lib.rs"
|
||||||
* A shortcut / implemented command to show all Hotkeys
|
* A shortcut / implemented command to show all Hotkeys
|
||||||
* git commit -m "message" does not work
|
* git commit -m "message" does not work
|
||||||
* Startup script section in sqishrc
|
* Startup script section in sqishrc
|
||||||
|
36
src/lib.rs
36
src/lib.rs
@ -221,39 +221,14 @@ 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);
|
||||||
@ -328,7 +303,6 @@ 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(|| {
|
||||||
();
|
();
|
||||||
@ -351,6 +325,7 @@ 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();
|
||||||
@ -378,7 +353,6 @@ 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