Skip to content

Commit ccd72fa

Browse files
authored
Error out when config.nu has no editor configured (#8282)
# Description Fixes #8245. Instead of trying to use `nano` or `notepad` as defaults, it errors out if finds that `buffer_editor` , $EDITOR, $VISUAL do not exist. If the PR is landed, Ill update the website as it means what its in there is no longer correct. ``` ❯ config nu Error: × No editor configured ╭─[entry #3:1:1] 1 │ config nu · ────┬──── · ╰── Please specify one via environment variables $EDITOR or $VISUAL ╰──── help: 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) ``` # User-Facing Changes # Tests + Formatting Make sure you've run and fixed any issues with these commands: - [X] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [X] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - [X] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
1 parent 03e688e commit ccd72fa

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

crates/nu-command/src/env/config/config_env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Command for ConfigEnv {
5858
let mut nu_config = config_path.clone();
5959
nu_config.push("env.nu");
6060

61-
let (item, config_args) = get_editor(engine_state, stack)?;
61+
let (item, config_args) = get_editor(engine_state, stack, call.head)?;
6262

6363
gen_command(call.head, nu_config, item, config_args, env_vars_str).run_with_input(
6464
engine_state,

crates/nu-command/src/env/config/config_nu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Command for ConfigNu {
5858
let mut nu_config = config_path.clone();
5959
nu_config.push("config.nu");
6060

61-
let (item, config_args) = get_editor(engine_state, stack)?;
61+
let (item, config_args) = get_editor(engine_state, stack, call.head)?;
6262

6363
gen_command(call.head, nu_config, item, config_args, env_vars_str).run_with_input(
6464
engine_state,

crates/nu-command/src/env/config/utils.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ use std::{collections::HashMap, path::PathBuf};
22

33
use nu_protocol::{
44
engine::{EngineState, Stack},
5-
Span, Spanned,
5+
ShellError, Span, Spanned,
66
};
77

88
use crate::ExternalCommand;
99

1010
pub(crate) fn get_editor(
1111
engine_state: &EngineState,
1212
stack: &mut Stack,
13-
) -> Result<(String, Vec<String>), nu_protocol::ShellError> {
13+
span: Span,
14+
) -> Result<(String, Vec<String>), ShellError> {
1415
let config = engine_state.get_config();
1516
let env_vars = stack.get_env_vars(engine_state);
1617
let editor = if !config.buffer_editor.is_empty() {
@@ -19,10 +20,17 @@ pub(crate) fn get_editor(
1920
value.as_string()
2021
} else if let Some(value) = env_vars.get("VISUAL") {
2122
value.as_string()
22-
} else if cfg!(target_os = "windows") {
23-
Ok("notepad".to_string())
2423
} else {
25-
Ok("nano".to_string())
24+
Err(ShellError::GenericError(
25+
"No editor configured".into(),
26+
"Please specify one via environment variables $EDITOR or $VISUAL".into(),
27+
Some(span),
28+
Some(
29+
"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)"
30+
.into(),
31+
),
32+
vec![],
33+
))
2634
}?;
2735
if let Some((a, b)) = editor.split_once(' ') {
2836
Ok((

0 commit comments

Comments
 (0)