Skip to content
Snippets Groups Projects
Commit 51b8c4d8 authored by Javier Martinez's avatar Javier Martinez Committed by Michael Aaron Murphy
Browse files

History Timestamps for Ion

parent 6b61760c
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,9 @@ use regex::Regex; ...@@ -4,6 +4,9 @@ use regex::Regex;
use small; use small;
use std::io::{self, Write}; use std::io::{self, Write};
use types; use types;
use std::time::{SystemTime, UNIX_EPOCH};
bitflags! { bitflags! {
struct IgnoreFlags: u8 { struct IgnoreFlags: u8 {
...@@ -107,8 +110,32 @@ impl ShellHistory for Shell { ...@@ -107,8 +110,32 @@ impl ShellHistory for Shell {
fn save_command_in_history(&self, command: &str) { fn save_command_in_history(&self, command: &str) {
if self.should_save_command(command) { if self.should_save_command(command) {
let variables = &self.variables;
// Mark the command in the context history // Mark the command in the context history
self.set_context_history_from_vars(); 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 if let Err(err) = self
.context .context
.as_ref() .as_ref()
......
...@@ -227,6 +227,12 @@ impl Default for Variables { ...@@ -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( map.insert(
"HISTORY_IGNORE".into(), "HISTORY_IGNORE".into(),
VariableType::Array(array!["no_such_command", "whitespace", "duplicates"]), VariableType::Array(array!["no_such_command", "whitespace", "duplicates"]),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment