scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.93k stars 380 forks source link

Filename completion on unquoted string #1057

Open mmjo opened 1 year ago

mmjo commented 1 year ago

Describe the bug

File completion when there is an open quote fails. I.e. "a b"/"x

To reproduce

mkdir empty cd empty mkdir d touch d/f

  1. cd empty
  2. Type: d/"<TAB>
  3. Get: d/"d/f"

Expected behavior

Get: d/f Or: d/"f"

Versions (please complete the following information)

Additional context

Initially the problem occurred with spaces in directory and filenames. Hence the typing of the " before the <TAB>.

Discussion in bug-readline mailing list, especially the message of the bash/readline maintainer, Chet Ramey: https://lists.gnu.org/archive/html/bug-readline/2023-09/msg00018.html

Debug trace

trace.txt

mmjo commented 1 year ago

Chet Ramey notes further (https://lists.gnu.org/archive/html/bug-readline/2023-10/msg00000.html):

This could be an opportunity for bash-completion to do a better job than bash's default completion.

It could note that ${COMP_WORDS[$COMP_CWORD]} differs from the word readline thinks is being completed, check whether readline's word is a subset of the current word, perform completions on the current word as it does now, and then filter out the prefix readline isn't going to use before returning the possible completions.