diff --git a/crates/nu-command/src/env/config/config_env.rs b/crates/nu-command/src/env/config/config_env.rs index 51e6e86246..dd0fad7a90 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 { let mut nu_config = config_path.clone(); nu_config.push("env.nu"); - let (item, config_args) = get_editor(engine_state, stack)?; + let (item, config_args) = get_editor(engine_state, stack, call.head)?; gen_command(call.head, nu_config, item, config_args, env_vars_str).run_with_input( engine_state, diff --git a/crates/nu-command/src/env/config/config_nu.rs b/crates/nu-command/src/env/config/config_nu.rs index 122aeaae24..f03f798e8d 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 { let mut nu_config = config_path.clone(); nu_config.push("config.nu"); - let (item, config_args) = get_editor(engine_state, stack)?; + let (item, config_args) = get_editor(engine_state, stack, call.head)?; gen_command(call.head, nu_config, item, config_args, env_vars_str).run_with_input( engine_state, diff --git a/crates/nu-command/src/env/config/utils.rs b/crates/nu-command/src/env/config/utils.rs index 107d35b476..4e1bfb5bf6 100644 --- a/crates/nu-command/src/env/config/utils.rs +++ b/crates/nu-command/src/env/config/utils.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, path::PathBuf}; use nu_protocol::{ engine::{EngineState, Stack}, - Span, Spanned, + ShellError, Span, Spanned, }; use crate::ExternalCommand; @@ -10,7 +10,8 @@ use crate::ExternalCommand; pub(crate) fn get_editor( engine_state: &EngineState, stack: &mut Stack, -) -> Result<(String, Vec), nu_protocol::ShellError> { + span: Span, +) -> Result<(String, Vec), ShellError> { let config = engine_state.get_config(); let env_vars = stack.get_env_vars(engine_state); let editor = if !config.buffer_editor.is_empty() { @@ -19,10 +20,17 @@ pub(crate) fn get_editor( value.as_string() } else if let Some(value) = env_vars.get("VISUAL") { value.as_string() - } else if cfg!(target_os = "windows") { - Ok("notepad".to_string()) } else { - Ok("nano".to_string()) + Err(ShellError::GenericError( + "No editor configured".into(), + "Please specify one via environment variables $EDITOR or $VISUAL".into(), + Some(span), + Some( + "Nushell's config file can be found with the command: $nu.config-path. For more help: (https://nushell.sh/book/configuration.html#configurations-with-built-in-commands)" + .into(), + ), + vec![], + )) }?; if let Some((a, b)) = editor.split_once(' ') { Ok((