From 0e1bfae13d7b0bc89dd46d5a6fe3177a4a038652 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Sun, 22 May 2022 19:32:52 +0200 Subject: [PATCH] Fallback for `config.buffer_editor` from `EDITOR` (#5614) For the reedline `buffer_editor` use the `EDITOR` and `VISUAL` environment variables as fallback. Same resolution order as #5607 Closes #5430 --- crates/nu-cli/src/repl.rs | 21 ++++++++++++++++++++- docs/sample_config/default_config.nu | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index b3b91f0d51..9a50618740 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -159,7 +159,26 @@ pub fn evaluate_repl( } }; - line_editor = line_editor.with_buffer_editor(config.buffer_editor.clone(), "nu".into()); + let buffer_editor = if !config.buffer_editor.is_empty() { + Some(config.buffer_editor.clone()) + } else { + stack + .get_env_var(engine_state, "EDITOR") + .map(|v| v.as_string().unwrap_or_default()) + .filter(|v| !v.is_empty()) + .or_else(|| { + stack + .get_env_var(engine_state, "VISUAL") + .map(|v| v.as_string().unwrap_or_default()) + .filter(|v| !v.is_empty()) + }) + }; + + line_editor = if let Some(buffer_editor) = buffer_editor { + line_editor.with_buffer_editor(buffer_editor, "nu".into()) + } else { + line_editor + }; if config.sync_history_on_enter { if is_perf_true { diff --git a/docs/sample_config/default_config.nu b/docs/sample_config/default_config.nu index f81bf33fc2..cae01621b0 100644 --- a/docs/sample_config/default_config.nu +++ b/docs/sample_config/default_config.nu @@ -190,7 +190,7 @@ let-env config = { completion_algorithm: "prefix" # prefix, fuzzy animate_prompt: false # redraw the prompt every second float_precision: 2 - buffer_editor: "emacs" # command that will be used to edit the current line buffer with ctrl+o + # buffer_editor: "emacs" # command that will be used to edit the current line buffer with ctrl+o, if unset fallback to $env.EDITOR and $env.VISUAL use_ansi_coloring: true filesize_format: "auto" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto edit_mode: emacs # emacs, vi