mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 05:18:27 +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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -287,10 +287,13 @@ fn main() -> Result<()> {
|
||||
binary_args.env_file,
|
||||
binary_args.login_shell.is_some(),
|
||||
);
|
||||
let history_path = config_files::create_history_path();
|
||||
|
||||
let ret_val =
|
||||
evaluate_repl(&mut engine_state, &mut stack, history_path, is_perf_true());
|
||||
let ret_val = evaluate_repl(
|
||||
&mut engine_state,
|
||||
&mut stack,
|
||||
config_files::NUSHELL_FOLDER,
|
||||
is_perf_true(),
|
||||
);
|
||||
if is_perf_true() {
|
||||
info!("repl eval {}:{}:{}", file!(), line!(), column!());
|
||||
}
|
||||
|
Reference in New Issue
Block a user