From 0011f4df566750f983f4db4379c531aad65d4b63 Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Sat, 26 Mar 2022 23:21:39 -0700 Subject: [PATCH] Check same-string-different-case in did_you_mean (#4991) --- crates/nu-protocol/src/shell_error.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index b80cc30cf2..7e1a8fa7b8 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -360,6 +360,15 @@ impl From> for ShellError { } pub fn did_you_mean(possibilities: &[String], tried: &str) -> Option { + // First see if we can find the same string just cased differently + let great_match_index = possibilities + .iter() + .position(|word| word.to_lowercase() == tried.to_lowercase()); + + if let Some(index) = great_match_index { + return Some(possibilities[index].to_owned()); + } + let mut possible_matches: Vec<_> = possibilities .iter() .map(|word| {