Do not add spaces after completions ending in "-"

Some programs use this to separate things in a word, see
https://github.com/spf13/cobra/pull/1249#discussion_r563605048

Require the token to be at least length 2 for the no-space behavior,
for completions of "-" like for python.
This commit is contained in:
Johannes Altmanninger 2021-01-25 18:44:33 +01:00
parent b5df9a7137
commit e27d97b02e
3 changed files with 3 additions and 4 deletions

View File

@ -194,8 +194,7 @@ Interactive improvements
- The interactive reader now allows ending a line in a logical operators (``&&`` and ``||``) instead of complaining about a missing command
(This was already syntactically valid, but interactive sessions didn't know about it yet).
- The prompt is reprinted after a background job exits (:issue:`1018`).
- fish no longer inserts a space after a completion ending in ``.`` or
``,`` is accepted (:issue:`6928`).
- fish no longer inserts a space after a completion ending in ``.``, ``,`` or ``-`` is accepted (:issue:`6928`).
- If a filename is invalid when first pressing Tab, but becomes valid, it will be completed properly on the next attempt (:issue:`6863`).
- ``help string match/replace/<subcommand>`` will show the help for string subcommands (:issue:`6786`).
- ``fish_key_reader`` sets the exit status to 0 when used with ``--help`` or ``--version`` (:issue:`6964`).

View File

@ -196,7 +196,7 @@ static complete_flags_t resolve_auto_space(const wcstring &comp, complete_flags_
if (flags & COMPLETE_AUTO_SPACE) {
new_flags &= ~COMPLETE_AUTO_SPACE;
size_t len = comp.size();
if (len > 0 && (std::wcschr(L"/=@:.,", comp.at(len - 1)) != nullptr))
if (len > 1 && (std::wcschr(L"/=@:.,-", comp.at(len - 1)) != nullptr))
new_flags |= COMPLETE_NO_SPACE;
}
return new_flags;

View File

@ -1868,7 +1868,7 @@ static uint32_t get_best_rank(const completion_list_t &comp) {
///
/// - If the list is empty, flash the terminal.
/// - If the list contains one element, write the whole element, and if the element does not end on
/// a '/', '@', ':', '.', ',' or a '=', also write a trailing space.
/// a '/', '@', ':', '.', ',', '-' or a '=', also write a trailing space.
/// - If the list contains multiple elements, insert their common prefix, if any and display
/// the list in the pager. Depending on terminal size and the length of the list, the pager
/// may either show less than a screenfull and exit or use an interactive pager to allow the