diff --git a/src/lib/shell/history.rs b/src/lib/shell/history.rs index 4e75815f6042e0fec6ff8acd7da3bcfec5b38bbf..1e357aa0629d07b5646bb2cf35f0978454b2f5d6 100644 --- a/src/lib/shell/history.rs +++ b/src/lib/shell/history.rs @@ -4,6 +4,9 @@ use regex::Regex; use small; use std::io::{self, Write}; use types; +use std::time::{SystemTime, UNIX_EPOCH}; + + bitflags! { struct IgnoreFlags: u8 { @@ -107,8 +110,32 @@ impl ShellHistory for Shell { fn save_command_in_history(&self, command: &str) { if self.should_save_command(command) { + let variables = &self.variables; + // Mark the command in the context history self.set_context_history_from_vars(); + + if variables.get_str_or_empty("HISTORY_TIMESTAMP") == "1" { + // Get current time stamp + let since_unix_epoch = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(); + let cur_time_sys = ["#", &since_unix_epoch.to_owned().to_string()].concat(); + + // Push current time to history + if let Err(err) = self + .context + .as_ref() + .unwrap() + .lock() + .unwrap() + .history + .push(cur_time_sys.into()) + { + eprintln!("ion: {}", err) + } + } + + + // Push command itself to history if let Err(err) = self .context .as_ref() diff --git a/src/lib/shell/variables/mod.rs b/src/lib/shell/variables/mod.rs index 818abdc7d5c364003f54d1301eb6f3bbf8bc91a7..a1170a5492bd310f4da4ae3a267a1f3f6d8a7a9a 100644 --- a/src/lib/shell/variables/mod.rs +++ b/src/lib/shell/variables/mod.rs @@ -227,6 +227,12 @@ impl Default for Variables { } } + // History Timestamps enabled variable, disabled by default + map.insert( + "HISTORY_TIMESTAMP".into(), + VariableType::Str("0".into()) + ); + map.insert( "HISTORY_IGNORE".into(), VariableType::Array(array!["no_such_command", "whitespace", "duplicates"]),