Fix function definitions potentially leaking as completions

This commit is contained in:
Johannes Altmanninger 2019-11-05 09:49:01 +01:00
parent 36693e4391
commit 4c73382231

View File

@ -655,6 +655,15 @@ static wcstring complete_function_desc(const wcstring &fn) {
bool has_description = function_get_desc(fn, result);
if (!has_description) {
function_get_definition(fn, result);
// Consider complete -a '(complete -C "prefix")':
// If some functions whose name starts with prefix and whose
// definition includes a line that starts with prefix, this line
// would be suggested as completion.
// Replace newlines by spaces to avoid these excess lines.
// The completion description will be shown in one line regardless.
for (wchar_t &c : result) {
if (c == L'\n') c = L' ';
}
}
return result;
}