create history file if it doesnt exit (#605)

This commit is contained in:
Fernando Herrera 2021-12-27 19:14:23 +00:00 committed by GitHub
parent 53330c5676
commit 5c94528fe2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
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 {
None
};
Some(history_path)
}
});
#[cfg(feature = "plugin")]
{