From 5c94528fe2af8bbc031c831762c2ca4a033bf6c4 Mon Sep 17 00:00:00 2001 From: Fernando Herrera Date: Mon, 27 Dec 2021 19:14:23 +0000 Subject: [PATCH] create history file if it doesnt exit (#605) --- src/main.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 051fa8d900..85e1d8b457 100644 --- a/src/main.rs +++ b/src/main.rs @@ -295,14 +295,20 @@ fn main() -> Result<()> { report_error(&working_set, &e); } - let history_path = if let Some(mut history_path) = nu_path::config_dir() { + let history_path = nu_path::config_dir().and_then(|mut history_path| { history_path.push("nushell"); history_path.push("history.txt"); - Some(history_path) - } else { - None - }; + if !history_path.exists() { + // Creating an empty file to store the history + match std::fs::File::create(&history_path) { + Ok(_) => Some(history_path), + Err(_) => None, + } + } else { + Some(history_path) + } + }); #[cfg(feature = "plugin")] {