diff --git a/crates/nu-cli/src/completions/directory_completions.rs b/crates/nu-cli/src/completions/directory_completions.rs index 2a539a0d3..6e712af08 100644 --- a/crates/nu-cli/src/completions/directory_completions.rs +++ b/crates/nu-cli/src/completions/directory_completions.rs @@ -63,7 +63,12 @@ impl Completer for DirectoryCompletion { match self.get_sort_by() { SortBy::Ascending => { - sorted_items.sort_by(|a, b| a.value.cmp(&b.value)); + sorted_items.sort_by(|a, b| { + // Ignore trailing slashes in folder names when sorting + a.value + .trim_end_matches(SEP) + .cmp(b.value.trim_end_matches(SEP)) + }); } SortBy::LevenshteinDistance => { sorted_items.sort_by(|a, b| { diff --git a/crates/nu-cli/src/completions/file_completions.rs b/crates/nu-cli/src/completions/file_completions.rs index d3d8858bc..4c6657aab 100644 --- a/crates/nu-cli/src/completions/file_completions.rs +++ b/crates/nu-cli/src/completions/file_completions.rs @@ -60,7 +60,12 @@ impl Completer for FileCompletion { match self.get_sort_by() { SortBy::Ascending => { - sorted_items.sort_by(|a, b| a.value.cmp(&b.value)); + sorted_items.sort_by(|a, b| { + // Ignore trailing slashes in folder names when sorting + a.value + .trim_end_matches(SEP) + .cmp(b.value.trim_end_matches(SEP)) + }); } SortBy::LevenshteinDistance => { sorted_items.sort_by(|a, b| {