History callbacks now allow piping
This commit is contained in:
parent
6fa2788161
commit
c06afb410c
@ -2,7 +2,6 @@
|
|||||||
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:
|
||||||
* 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
|
||||||
|
|
||||||
@ -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+Q or Ctrl+D : Quits the shell immediatly
|
||||||
* Ctrl+U : Clears currently written line
|
* Ctrl+U : Clears currently written line
|
||||||
* Alt+. : Appends the last word from previous command
|
* 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+A : Jumps to the end of the line
|
||||||
* Ctrl+E : Jumps to the start of the line
|
* Ctrl+E : Jumps to the start of the line
|
||||||
* Ctrl+C : Clears the current line and starts a new one
|
* Ctrl+C : Clears the current line and starts a new one
|
||||||
|
|
||||||
### In Text:
|
### In Text:
|
||||||
* !12 : Reruns command number 12 from history (Replace the number with anything)
|
* !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
|
* !! : Appends the previous command to the current line. Same principle as !12.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -546,6 +546,10 @@ pub mod shell {
|
|||||||
'.' => {
|
'.' => {
|
||||||
append_prev_arg(&mut mycommand, &mut current_pos, &mut max_pos);
|
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);
|
||||||
|
},
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
|
@ -20,6 +20,8 @@ pub fn write_to_history(command: &str) -> Result<(), std::io::Error> {
|
|||||||
Err(_) => 1
|
Err(_) => 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let command = command.replace('\n', "\\n");
|
||||||
|
|
||||||
writeln!(file, "{} {}", number, command.trim())?;
|
writeln!(file, "{} {}", number, command.trim())?;
|
||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
@ -93,12 +95,17 @@ pub fn get_hist_from_number(number: &i32) -> Option<String> {
|
|||||||
|
|
||||||
pub fn treat_history_callback(line: &str) -> Option<String> {
|
pub fn treat_history_callback(line: &str) -> Option<String> {
|
||||||
let mut mystring = String::from(line);
|
let mut mystring = String::from(line);
|
||||||
mystring = mystring.trim().to_string();
|
let temp = mystring.split_whitespace().collect::<Vec<&str>>();
|
||||||
|
let mystring = temp.first().unwrap_or(&line);
|
||||||
let mut chars = mystring.chars();
|
let mut chars = mystring.chars();
|
||||||
|
let args = &temp[1..];
|
||||||
//Skip the !
|
//Skip the !
|
||||||
chars.next();
|
chars.next();
|
||||||
let mynbr: i32 = chars.as_str().parse().unwrap();
|
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<String> {
|
pub fn get_prev_arg() -> Option<String> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user