SQLite History MVP with timestamp, duration, working directory, exit status metadata (#5721)

This PR adds support for an SQLite history via nushell/reedline#401

The SQLite history is enabled by setting history_file_format: "sqlite" in config.nu.

* somewhat working sqlite history
* Hook up history command
* Fix error in SQlitebacked with empty lines

When entering an empty line there previously was the "No command run"
error with `SqliteBackedHistory` during addition of the metadata

May be considered a temporary fix

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
phiresky
2022-06-14 22:53:33 +02:00
committed by GitHub
parent 534e1fc3ce
commit 42dbfd1fa0
12 changed files with 243 additions and 127 deletions

View File

@ -6,13 +6,11 @@ use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
use nu_protocol::{PipelineData, Span, Spanned};
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
pub(crate) const NUSHELL_FOLDER: &str = "nushell";
const CONFIG_FILE: &str = "config.nu";
const ENV_FILE: &str = "env.nu";
const LOGINSHELL_FILE: &str = "login.nu";
const HISTORY_FILE: &str = "history.txt";
pub(crate) fn read_config_file(
engine_state: &mut EngineState,
@ -104,7 +102,6 @@ pub(crate) fn read_config_file(
info!("read_config_file {}:{}:{}", file!(), line!(), column!());
}
}
pub(crate) fn read_loginshell_file(
engine_state: &mut EngineState,
stack: &mut Stack,
@ -124,20 +121,3 @@ pub(crate) fn read_loginshell_file(
info!("read_loginshell_file {}:{}:{}", file!(), line!(), column!());
}
}
pub(crate) fn create_history_path() -> Option<PathBuf> {
nu_path::config_dir().and_then(|mut history_path| {
history_path.push(NUSHELL_FOLDER);
history_path.push(HISTORY_FILE);
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)
}
})
}