diff --git a/Cargo.toml b/Cargo.toml index 06cebda215..b4552c915b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -325,6 +325,7 @@ bench = false # changing versions in each sub-crate of the workspace is tedious [patch.crates-io] # reedline = { git = "https://github.com/nushell/reedline", branch = "main" } +reedline = { git = "https://github.com/mrdgo/reedline.git", rev = "3a6ad518", features = ["bashisms", "sqlite"] } # nu-ansi-term = {git = "https://github.com/nushell/nu-ansi-term.git", branch = "main"} # Run all benchmarks with `cargo bench` diff --git a/crates/nu-cli/src/commands/commandline/edit.rs b/crates/nu-cli/src/commands/commandline/edit.rs index 64f3ae2a08..05d9c63fa3 100644 --- a/crates/nu-cli/src/commands/commandline/edit.rs +++ b/crates/nu-cli/src/commands/commandline/edit.rs @@ -26,6 +26,11 @@ impl Command for SubCommand { "replaces the current contents of the buffer (default)", Some('r'), ) + .switch( + "accept", + "immediately executes the result after edit", + Some('A'), + ) .required( "str", SyntaxShape::String, @@ -61,6 +66,13 @@ impl Command for SubCommand { repl.buffer = str; repl.cursor_pos = repl.buffer.len(); } + + if call.has_flag(engine_state, stack, "accept")? { + if let Ok(mut flag) = engine_state.immediately_execute.lock() { + *flag = true; + } + } + Ok(Value::nothing(call.head).into_pipeline_data()) } } diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index a64ecbcefe..cb1e1ad583 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -481,7 +481,18 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) { start_time = std::time::Instant::now(); line_editor = line_editor.with_transient_prompt(transient_prompt); - let input = line_editor.read_line(nu_prompt); + + let input = line_editor.read_line( + nu_prompt, + if let Ok(mut flag) = engine_state.immediately_execute.lock() { + let ret = *flag; + *flag = false; + ret + } else { + false + }, + ); + // we got our inputs, we can now drop our stack references // This lists all of the stack references that we have cleaned up line_editor = line_editor diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index bc6d7a2eb1..accc08ba95 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -95,6 +95,7 @@ pub struct EngineState { pub config: Arc, pub pipeline_externals_state: Arc<(AtomicU32, AtomicU32)>, pub repl_state: Arc>, + pub immediately_execute: Arc>, pub table_decl_id: Option, #[cfg(feature = "plugin")] pub plugin_path: Option, @@ -180,6 +181,7 @@ impl EngineState { startup_time: -1, is_debugging: IsDebugging::new(false), debugger: Arc::new(Mutex::new(Box::new(NoopDebugger))), + immediately_execute: Arc::new(Mutex::new(false)), } }