I am playing around with the programmable completion of Bash and there is something I don't quite understand.
Environment
This is what I get when I run bash --version in my terminal.
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. I am running all this in an Ubuntu 22.04.2 LTS
I have two files.
FILE 1 (The script)
The first one is the script for which I want to have programmable completion which looks like this:
#!/usr/bin/env bash #Script: dothis echo "COMMAND: $0 $@" As you can see this is a dummy script that prints the name of the script followed by the arguments.
FILE 2 (Programmable Completion Script)
The second file, which is the file in charge of the programmable completion for the previous script, looks like this:
#!/usr/bin/env bash _dothis_completions(){ # -S suffix COMPREPLY=($(compgen -A user -S '_suffix' "${COMP_WORDS[1]}")) # -P prefix #COMPREPLY=($(compgen -A user -P 'prefix_' "${COMP_WORDS[1]}")) } complete -F _dothis_completions dothis When I use it with the option -S (to attach a suffix to the suggestions) it works perfectly. It gives me as suggestions the different users in the system with _suffix attached at the end.
Now, if I modify the script for programmable completion to look like this:
#!/usr/bin/env bash _dothis_completions(){ # -S suffix #COMPREPLY=($(compgen -A user -S '_suffix' "${COMP_WORDS[1]}")) # -P prefix COMPREPLY=($(compgen -A user -P 'prefix_' "${COMP_WORDS[1]}")) } complete -F _dothis_completions dothis (Please notice that now I want to use the -P flag to attach the prefix prefix_ to all suggestions)
And I try it again in the command line, it does not work.
Does anyone know why this is not working?
Thanks a lot in advance!
Update (July 29th 2023)
I decided to use the programmable completion of Bash from Zsh and seems to be working without issues.
Hope this bit of information will help us find the answer to why the "-P" flag does not work properly in Bash.