mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:34:58 +02:00
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:
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user