History callbacks now allow piping
This commit is contained in:
@ -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<String> {
|
||||
|
||||
pub fn treat_history_callback(line: &str) -> Option<String> {
|
||||
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 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<String> {
|
||||
|
Reference in New Issue
Block a user