diff --git a/README.md b/README.md index a620a42..638201e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Rust Shell. This is an attempt to create a simple shell in Rust, because why not. TODO: -* A shortcut / implemented command to show all Hotkeys * git commit -m "message" does not work * Startup script section in sqishrc @@ -15,13 +14,14 @@ Some shortcuts are built in. They may be unique to Sqish or be copied from Zsh f * Ctrl+Q or Ctrl+D : Quits the shell immediatly * Ctrl+U : Clears currently written line * Alt+. : Appends the last word from previous command +* Alt+! : Show a list of the user-configured hotkeys * Ctrl+A : Jumps to the end of the line * Ctrl+E : Jumps to the start of the line * Ctrl+C : Clears the current line and starts a new one ### In Text: -* !12 : Reruns command number 12 from history (Replace the number with anything) -* !! : Appends the previous command to the current line +* !12 : Returns command number 12 from history (Replace the number 12 12 12 12 12 12 12 12 12 12 12 12 with any number from history). You can add commands after it, like: "!12 | grep squirrel" +* !! : Appends the previous command to the current line. Same principle as !12. diff --git a/src/lib.rs b/src/lib.rs index d252a84..07c2b7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -546,6 +546,10 @@ pub mod shell { '.' => { append_prev_arg(&mut mycommand, &mut current_pos, &mut max_pos); }, + '!' => { + let mut cmd = format!("echo -- ALIASES --> {:?}", conf.hotkeys); + run_cmd(&mut cmd, &mut current_number, &mut conf, &mut stdout); + }, _ => (), }; diff --git a/src/shell/history.rs b/src/shell/history.rs index e8de9f4..5810c00 100644 --- a/src/shell/history.rs +++ b/src/shell/history.rs @@ -20,6 +20,8 @@ pub fn write_to_history(command: &str) -> Result<(), std::io::Error> { Err(_) => 1 }; + let command = command.replace('\n', "\\n"); + writeln!(file, "{} {}", number, command.trim())?; return Ok(()) } @@ -93,12 +95,17 @@ pub fn get_hist_from_number(number: &i32) -> Option { pub fn treat_history_callback(line: &str) -> Option { let mut mystring = String::from(line); - mystring = mystring.trim().to_string(); + let temp = mystring.split_whitespace().collect::>(); + let mystring = temp.first().unwrap_or(&line); let mut chars = mystring.chars(); + let args = &temp[1..]; //Skip the ! chars.next(); let mynbr: i32 = chars.as_str().parse().unwrap(); - get_hist_from_number(&mynbr) + match get_hist_from_number(&mynbr) { + Some(h) => return Some(format!("{} {}", h, args.join(" "))), + None => return None, + } } pub fn get_prev_arg() -> Option {