diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 35ff7489b..8092b9c5f 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -106,6 +106,14 @@ pub fn evaluate_repl( let config = engine_state.get_config(); + // Setup history_isolation aka "history per session" + let history_isolation = config.history_isolation; + let history_session_id = if history_isolation { + Reedline::create_history_session_id() + } else { + None + }; + start_time = std::time::Instant::now(); let history_path = crate::config_files::get_history_path( nushell_path, @@ -124,7 +132,9 @@ pub fn evaluate_repl( SqliteBackedHistory::with_file(history_path.to_path_buf()).into_diagnostic()?, ), }; - line_editor = line_editor.with_history(history); + line_editor = line_editor + .with_history_session_id(history_session_id) + .with_history(history); }; perf( "setup history", diff --git a/crates/nu-protocol/src/config.rs b/crates/nu-protocol/src/config.rs index ac9847bf9..5842c5f19 100644 --- a/crates/nu-protocol/src/config.rs +++ b/crates/nu-protocol/src/config.rs @@ -86,6 +86,7 @@ pub struct Config { pub max_history_size: i64, pub sync_history_on_enter: bool, pub history_file_format: HistoryFileFormat, + pub history_isolation: bool, pub log_level: String, pub keybindings: Vec, pub menus: Vec, @@ -129,6 +130,7 @@ impl Default for Config { max_history_size: i64::MAX, sync_history_on_enter: true, history_file_format: HistoryFileFormat::PlainText, + history_isolation: false, log_level: String::new(), keybindings: Vec::new(), menus: Vec::new(), @@ -419,6 +421,9 @@ impl Value { let value = &vals[index]; let key2 = cols[index].as_str(); match key2 { + "history_isolation" => { + try_bool!(cols, vals, index, span, history_isolation) + } "sync_on_enter" => { try_bool!(cols, vals, index, span, sync_history_on_enter) } diff --git a/crates/nu-utils/src/sample_config/default_config.nu b/crates/nu-utils/src/sample_config/default_config.nu index 7d2c70835..135207f0c 100644 --- a/crates/nu-utils/src/sample_config/default_config.nu +++ b/crates/nu-utils/src/sample_config/default_config.nu @@ -266,6 +266,7 @@ let-env config = { max_size: 10000 # Session has to be reloaded for this to take effect sync_on_enter: true # Enable to share history between multiple sessions, else you have to close the session to write history to file file_format: "plaintext" # "sqlite" or "plaintext" + history_isolation: true # true enables history isolation, false disables it. true will allow the history to be isolated to the current session. false will allow the history to be shared across all sessions. } completions: { case_sensitive: false # set to true to enable case-sensitive completions