sh: improve command completion
When multiple matches are found, we keep the provided string on the
input line and print unique matches as suggestions.
But the multiple matches might be the same command found in different
directories, so we should deduplicate the matches first and then decide
whether to autocomplete the command or not, based on the number of
unique matches.
(cherry picked from commit b8ff849cbddfee3404d6550cf98f53d6bb617707)