2

I have a script (let's call it myscript) and I want to enable autocomplete arguments for files with a specific extension (e.g. .txt). I can do this simply with:

complete -f -X '!*.txt' myscript

Then, given the files a, b, a.txt, b.txt, and ab.txt typing "myscript" and hitting tab twice gives me:

$ myscript
a.txt  ab.txt  b.txt

What I want to do is allow wildcards to filter this further, e.g. if I type "myscript *b*" and hit tab twice I want to see:

$ myscript *b*
ab.txt  b.txt

Unfortunately this doesn't give me any autocompletion. If I remove the custom autocomplete (or pass -o bashdefault to complete) it gives me:

$ myscript *b*
ab.txt  b  b.txt

I don't want to see b in the results or have it passed to the script if I hit enter. Is there any way to get around this?

1
  • This is a general problem with bash custom completion (we've had the same question about cd several times, unanswered so far). It works in zsh. Apr 10, 2017 at 20:18

0

You must log in to answer this question.

Browse other questions tagged .