From 22a839b80d9bd175fd16839b06b595145b485ff1 Mon Sep 17 00:00:00 2001
From: stratact <stratact1@gmail.com>
Date: Tue, 12 Jun 2018 17:28:46 -0700
Subject: [PATCH] Make `$HISTORY_IGNORE` have proper defaults and add
 `duplicates` to the manual

---
 manual/src/ch13-00-history.md  |  3 ++-
 src/lib/shell/variables/mod.rs | 27 +++++++++++++++------------
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/manual/src/ch13-00-history.md b/manual/src/ch13-00-history.md
index 931565ea..b20b6fc7 100644
--- a/manual/src/ch13-00-history.md
+++ b/manual/src/ch13-00-history.md
@@ -31,12 +31,13 @@ Ideally, this value should be the same as `HISTFILE_SIZE`
 Specifies which commands should **NOT** be saved in the history.
 This is an array and defaults to an **empty array**, meaning that all commands will be saved.
 Each element of the array can take one of the following options:
-- **all** -> All commands are ignored, nothing will be saved in the history
+- **all** -> All commands are ignored, nothing will be saved in the history.
 - **no_such_command** -> Commands which return `NO_SUCH_COMMAND` will not be saved in the history.
 - **whitespace** -> Commands which start with a [whitespace character](https://doc.rust-lang.org/stable/reference/whitespace.html) will not be saved in the
 history.
 - **regex:xxx** -> Where xxx is treated as a [regular expression](https://doc.rust-lang.org/regex/regex/index.html).
 Commands which match this regular expression will not be saved in the history.
+- **duplicates** -> All preceding duplicate commands are removed/ignored from the history after a matching command is entered.
 
 **Notes**
 - You can specify as many elements as you want.
diff --git a/src/lib/shell/variables/mod.rs b/src/lib/shell/variables/mod.rs
index 662ceba5..92915123 100644
--- a/src/lib/shell/variables/mod.rs
+++ b/src/lib/shell/variables/mod.rs
@@ -38,11 +38,11 @@ pub struct Variables<'a> {
 
 impl<'a> Default for Variables<'a> {
     fn default() -> Self {
-        let mut map = FnvHashMap::with_capacity_and_hasher(64, Default::default());
-        map.insert("DIRECTORY_STACK_SIZE".into(), "1000".into());
-        map.insert("HISTORY_SIZE".into(), "1000".into());
-        map.insert("HISTFILE_SIZE".into(), "100000".into());
-        map.insert(
+        let mut map_vars = FnvHashMap::with_capacity_and_hasher(64, Default::default());
+        map_vars.insert("DIRECTORY_STACK_SIZE".into(), "1000".into());
+        map_vars.insert("HISTORY_SIZE".into(), "1000".into());
+        map_vars.insert("HISTFILE_SIZE".into(), "100000".into());
+        map_vars.insert(
             "PROMPT".into(),
             "${x::1B}]0;${USER}: \
              ${PWD}${x::07}${c::0x55,bold}${USER}${c::default}:${c::0x4B}${SWD}${c::default}# \
@@ -51,15 +51,15 @@ impl<'a> Default for Variables<'a> {
         );
 
         // Set the PID, UID, and EUID variables.
-        map.insert(
+        map_vars.insert(
             "PID".into(),
             getpid().ok().map_or("?".into(), |id| id.to_string()),
         );
-        map.insert(
+        map_vars.insert(
             "UID".into(),
             getuid().ok().map_or("?".into(), |id| id.to_string()),
         );
-        map.insert(
+        map_vars.insert(
             "EUID".into(),
             geteuid().ok().map_or("?".into(), |id| id.to_string()),
         );
@@ -67,11 +67,14 @@ impl<'a> Default for Variables<'a> {
         // Initialize the HISTFILE variable
         if let Ok(base_dirs) = BaseDirectories::with_prefix("ion") {
             if let Ok(path) = base_dirs.place_data_file("history") {
-                map.insert("HISTFILE".into(), path.to_str().unwrap_or("?").into());
-                map.insert("HISTFILE_ENABLED".into(), "1".into());
+                map_vars.insert("HISTFILE".into(), path.to_str().unwrap_or("?").into());
+                map_vars.insert("HISTFILE_ENABLED".into(), "1".into());
             }
         }
 
+        let mut map_arrays = FnvHashMap::with_capacity_and_hasher(64, Default::default());
+        map_arrays.insert("HISTORY_IGNORE".into(), array!["no_such_command", "whitespace", "duplicates"]);
+
         // Initialize the PWD (Present Working Directory) variable
         env::current_dir().ok().map_or_else(
             || env::set_var("PWD", "?"),
@@ -90,8 +93,8 @@ impl<'a> Default for Variables<'a> {
         Variables {
             parent:    None,
             hashmaps:  RefCell::new(FnvHashMap::with_capacity_and_hasher(64, Default::default())),
-            arrays:    RefCell::new(FnvHashMap::with_capacity_and_hasher(64, Default::default())),
-            variables: RefCell::new(map),
+            arrays:    RefCell::new(map_arrays),
+            variables: RefCell::new(map_vars),
             aliases:   RefCell::new(FnvHashMap::with_capacity_and_hasher(64, Default::default())),
             functions: RefCell::new(FnvHashMap::with_capacity_and_hasher(64, Default::default())),
             flags:     Cell::new(0),
-- 
GitLab