diff --git a/crates/nu-command/src/env/config/config_env.rs b/crates/nu-command/src/env/config/config_env.rs index 9e91e77f48..ec41bf2537 100644 --- a/crates/nu-command/src/env/config/config_env.rs +++ b/crates/nu-command/src/env/config/config_env.rs @@ -58,7 +58,7 @@ impl Command for ConfigEnv { nu_config.push("env.nu"); let name = Spanned { - item: get_editor(engine_state, stack), + item: get_editor(engine_state, stack)?, span: Span { start: 0, end: 0 }, }; diff --git a/crates/nu-command/src/env/config/config_nu.rs b/crates/nu-command/src/env/config/config_nu.rs index 6eb9ff63d1..55a6c98ab6 100644 --- a/crates/nu-command/src/env/config/config_nu.rs +++ b/crates/nu-command/src/env/config/config_nu.rs @@ -58,7 +58,7 @@ impl Command for ConfigNu { nu_config.push("config.nu"); let name = Spanned { - item: get_editor(engine_state, stack), + item: get_editor(engine_state, stack)?, span: Span { start: 0, end: 0 }, }; diff --git a/crates/nu-command/src/env/config/utils.rs b/crates/nu-command/src/env/config/utils.rs index 91df864a61..f0c07a6f70 100644 --- a/crates/nu-command/src/env/config/utils.rs +++ b/crates/nu-command/src/env/config/utils.rs @@ -1,17 +1,20 @@ use nu_protocol::engine::{EngineState, Stack}; -pub(crate) fn get_editor(engine_state: &EngineState, stack: &mut Stack) -> String { +pub(crate) fn get_editor( + engine_state: &EngineState, + stack: &mut Stack, +) -> Result { let config = engine_state.get_config(); let env_vars = stack.get_env_vars(engine_state); if !config.buffer_editor.is_empty() { - config.buffer_editor.clone() + Ok(config.buffer_editor.clone()) } else if let Some(value) = env_vars.get("EDITOR") { - value.as_string().expect("Unknown type") + value.as_string() } else if let Some(value) = env_vars.get("VISUAL") { - value.as_string().expect("Unknown type") + value.as_string() } else if cfg!(target_os = "windows") { - "notepad".to_string() + Ok("notepad".to_string()) } else { - "nano".to_string() + Ok("nano".to_string()) } }