deltaskelta deltaskelta - 2 months ago 5x
Bash Question

How can I `source` a file on my path and have it tab-complete?

I have a shell script that I want to run with

and it is on my path so if I start typing the name and hit tab it autocompletes...

but if I try this...

source foo (then hit the tab button)

it does not autocomplete. It is searching my working directory, but not searching my path. Is there anyway to make it find the file that is in my path?

I have bash version


You can put this into your bashrc:

complete -c source

-c stands for command names which will effectively search in PATH. But that requires that the files are executable. You could elaborate on that and program a custom completion function which uses find to retrieve all shell scripts in PATH.