diff --git a/complete.cpp b/complete.cpp index 76e8e4e81..1f3cc6564 100644 --- a/complete.cpp +++ b/complete.cpp @@ -324,9 +324,9 @@ completion_t &completion_t::operator=(const completion_t &him) return *this; } -bool completion_t::is_alphabetically_less_than(const completion_t &a, const completion_t &b) +bool completion_t::is_naturally_less_than(const completion_t &a, const completion_t &b) { - return a.completion < b.completion; + return wcsfilecmp(a.completion.c_str(), b.completion.c_str()) < 0; } bool completion_t::is_alphabetically_equal_to(const completion_t &a, const completion_t &b) diff --git a/complete.h b/complete.h index 36f1d6a12..99dcbf6a0 100644 --- a/complete.h +++ b/complete.h @@ -123,7 +123,9 @@ class completion_t completion_t &operator=(const completion_t &); /* Compare two completions. No operating overlaoding to make this always explicit (there's potentially multiple ways to compare completions). */ - static bool is_alphabetically_less_than(const completion_t &a, const completion_t &b); + + /* "Naturally less than" means in a natural ordering, where digits are treated as numbers. For example, foo10 is naturally greater than foo2 (but alphabetically less than it) */ + static bool is_naturally_less_than(const completion_t &a, const completion_t &b); static bool is_alphabetically_equal_to(const completion_t &a, const completion_t &b); }; diff --git a/expand.cpp b/expand.cpp index c908cd9df..969fabacc 100644 --- a/expand.cpp +++ b/expand.cpp @@ -1923,7 +1923,7 @@ int expand_string(const wcstring &input, std::vector &output, expa case 1: { res = EXPAND_WILDCARD_MATCH; - std::sort(expanded.begin(), expanded.end(), completion_t::is_alphabetically_less_than); + std::sort(expanded.begin(), expanded.end(), completion_t::is_naturally_less_than); out->insert(out->end(), expanded.begin(), expanded.end()); break; } diff --git a/reader.cpp b/reader.cpp index 13937f114..5231699fe 100644 --- a/reader.cpp +++ b/reader.cpp @@ -867,7 +867,7 @@ bool reader_data_t::expand_abbreviation_as_necessary(size_t cursor_backtrack) /** Sorts and remove any duplicate completions in the list. */ static void sort_and_make_unique(std::vector &l) { - sort(l.begin(), l.end(), completion_t::is_alphabetically_less_than); + sort(l.begin(), l.end(), completion_t::is_naturally_less_than); l.erase(std::unique(l.begin(), l.end(), completion_t::is_alphabetically_equal_to), l.end()); }