Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion for options with comma-separated values loses its prefix #240

Open
Lekensteyn opened this issue Oct 11, 2018 · 8 comments
Open

Comments

@Lekensteyn
Copy link
Collaborator

Lekensteyn commented Oct 11, 2018

commit 021058b tried to extend completion such that usermod -G root,systemd-<TAB> suggests possible completions for systemd-.

It works when only a single candidate is available (e.g. root,systemd-core<TAB> -> root,systemd-coredump), but when multiple completions are available, the prefix (root,) is dropped (e.g. root,systemd-<TAB> -> systemd- with initially no further suggestions).

This problem was first noticed when using the tshark -O http,t<TAB> option.

Reproducer (change XDG_DATA_DIRS to avoid loading completions from default path):

$ bash --rcfile <(echo 'XDG_DATA_DIRS=/nonexistent; . ./bash_completion')
$ usermod -G root,systemd-<TAB>

Environment:

  • Distribution: Arch Linux
  • bash 4.4.023-1
  • bash-completion 2.8-1 and git master 2.1-871-gc9c14da4
@scop
Copy link
Owner

scop commented Oct 11, 2018

It doesn't fail that way for me on Ubuntu 18, bash 4.4.19, current bash-completion master. Neither does tshark, it keeps the preceding comma separated completions as well.

$ usermod -G root,systemd-<TAB>
systemd-journal   systemd-network   systemd-resolve   systemd-timesync  
$ usermod -G root,systemd-

@Lekensteyn
Copy link
Collaborator Author

Lekensteyn commented Oct 11, 2018

Odd, perhaps it is some shell option that causes this? I reproduced the issue from the git tree with:

bash --rcfile <(echo . ./bash_completion)

so it should not be caused by any form of customization.

Edit: I was also able to reproduce this issue on Ubuntu 18.04 which ships with bash 4.4.18-2ubuntu1.
Do you have any special readline options?

Setting COMP_WORDBREAKS+=, seems to "improve" things as it matches the expected behavior, but now usermod -G root,--<TAB> is also being completed as option. Related question here with (unsatisfatory) answers: https://unix.stackexchange.com/questions/124539/bash-completion-for-comma-separated-values

@scop
Copy link
Owner

scop commented Oct 14, 2018

I tried to reproduce with the same command as you, ditto in a new shell started with bash --norc, but failed, it Just Works for me. The only customized readline setting I have is set show-all-if-ambiguous on in ~/.inputrc. Turning that off didn't seem to make a difference.

@Lekensteyn
Copy link
Collaborator Author

Really strange, perhaps it is a terminal thing? I can still reproduce it from Kubuntu 18.04.1 (no updates installed):

script -c "bash --rcfile <(echo 'XDG_DATA_DIRS=/nonexistent; . ./bash_completion') -x" output.txt
# Then type: "usermod -G root,systemd-<TAB>"
# followed by Ctrl-C and Ctrl-D (exit)

Over SSH or through Konsole (in the GUI) does not make a difference and produces the same output:
output.txt

Observe the last line: ^G^H^H^H^H^H^H^H^H^H^H^H^H^H^[[5Psystemd-
That's a bell, 13 times backspace (erases root,systemd-), CSI 5 P (delete 5 characters on the current line according to console_codes(4)), then insert systemd-. IOW, it replaces usermod -G root,systemd- by usermod -G systemd- which is what I am observing (without set -x).

@scop
Copy link
Owner

scop commented Oct 15, 2018

Here's my output for comparison. Didn't spot anything obvious in the diff on a quick look: output.txt

@Lekensteyn
Copy link
Collaborator Author

Can you reproduce it with a different user on the same system? Have you set the INPUTRC environment variable? strace reveals that files are search in this order (first match);

  • $INPUTRC
  • ~/.inputrc
  • /etc/inputrc

What is your output for echo $TERM? Mine says xterm-256color.

@scop
Copy link
Owner

scop commented Oct 17, 2018

INPUTRC is not set, and TERM is the same as yours.

~/.inputrc contents:

$include /etc/inputrc
set show-all-if-ambiguous on

...but I can reproduce with another user on this system. Cool, now I have something to look into when I find some time.

@scop
Copy link
Owner

scop commented Oct 17, 2018

It's the set show-all-if-ambiguous on. Commenting that out I can reproduce with my user too.

gitster pushed a commit to git/git that referenced this issue Feb 24, 2020
These options are available since git v2.15, but somehow
eluded from the completion script.

Note that while --color-moved-ws= accepts comma-separated
list of values, there is no (easy?) way to make it work
with completion (see e.g. [1]).

[1]: scop/bash-completion#240

Acked-by: Matheus Tavares Bernardino <matheus.bernardino@usp.br>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitster pushed a commit to git/git that referenced this issue Jul 15, 2020
The completion for diff command was added in fd0bc17 but
missed the show command which also supports --color-moved[-ws].

This suffers from the very same problem [1] as the referenced
commit: no comma-separated list completion for --color-moved-ws.

[1]: scop/bash-completion#240

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants