From 51b8c4d80233dd025264d3c35aa65b006360d89b Mon Sep 17 00:00:00 2001
From: Javier Martinez <hoogmin@gmail.com>
Date: Sat, 28 Jul 2018 23:53:56 +0000
Subject: [PATCH] History Timestamps for Ion

---
 src/lib/shell/history.rs       | 27 +++++++++++++++++++++++++++
 src/lib/shell/variables/mod.rs |  6 ++++++
 2 files changed, 33 insertions(+)

diff --git a/src/lib/shell/history.rs b/src/lib/shell/history.rs
index 4e75815f..1e357aa0 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 818abdc7..a1170a54 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"]),
-- 
GitLab