mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-28 01:11:15 -03:00
Use natural (digit-sequence-aware) sorting for wildcard expansion
Fixes #1993
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -1923,7 +1923,7 @@ int expand_string(const wcstring &input, std::vector<completion_t> &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;
|
||||
}
|
||||
|
||||
@@ -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<completion_t> &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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user