From 9264325e575c5b52faa9822e7ceaaa17beab221b Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Mon, 10 Aug 2020 20:58:53 -0500 Subject: [PATCH] Make history file location configurable (#2320) * Make history location configurable Add history-path to your config if you want an alternate history file location * use IndexMap.get() instead of index Co-authored-by: Amanita Muscaria --- crates/nu-cli/src/cli.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index b86d06ac1b..a18767eb0e 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -203,12 +203,28 @@ pub struct History; impl History { pub fn path() -> PathBuf { const FNAME: &str = "history.txt"; - config::user_data() + let default = config::user_data() .map(|mut p| { p.push(FNAME); p }) - .unwrap_or_else(|_| PathBuf::from(FNAME)) + .unwrap_or_else(|_| PathBuf::from(FNAME)); + + let cfg = crate::data::config::config(Tag::unknown()); + if let Ok(c) = cfg { + match &c.get("history-path") { + Some(Value { + value: UntaggedValue::Primitive(p), + .. + }) => match p { + Primitive::String(path) => PathBuf::from(path), + _ => default, + }, + _ => default, + } + } else { + default + } } }