Is there a way to do bash completion of a file path (like the ls program), but only for a certain argument? I've been puzzling over the documentation: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins
I'd like to use the -F
option to setup my own function, however I only want file path completion for one of the sub-commands of my program.
Note that it is straightforward to complete using compgen -f
, however this returns a list of complete paths, e.g.:
# compgen -f /bin/
/bin/[
/bin/bash
/bin/cat
/bin/chmod
/bin/cp
/bin/csh
<snip>
However ls completes like this:
# ls /bin/
[* cat* cp* date* df* ed*
hostname* ksh* link* ls* mv* ps*
<snip>
I believe there is only one COMPREPLY
list sent back to bash from a completion routine, and there seems to be no way to distinguish between the full program argument and the portion of it that gets displayed by bash. Unless there is some trick I can use.
Unfortunately the full path strings can very quickly become unwieldy, particularly for large programming projects with lots of files in the directories.