Bash – Why does path-completion in bash not always work

autocompletebashcommand line

With different bash-environments (different installations) I have different behaviors in terms of path-completion when hitting TAB on the command line after . Where is this handled?

One specific example:

I run cmake with a -D-argument:

cmake -DCMAKE_TOOLCHAIN_FILE=~/x-too<TAB>

it does nothing. Whereas (notice the space between = and ~

cmake -DCMAKE_TOOLCHAIN_FILE= ~/x-too<TAB> 

completes to

cmake -DCMAKE_TOOLCHAIN_FILE= ~/x-tools

On other systems it even works with no space between = and ~.

Where do I find the related configuration-files and values?

Best Answer

Linux autocompletions work with complete.

 ]➬complete -p  cmake
 complete -F _cmake cmake

So _cmake is in charge.

]➬type _cmake > cmake.sh

And now just see/debug it. You modify in for example _cmake_mine and call to test it:

. cmake.sh
complete -F _cmake_mine cmake

To get help for any builtin bash command:

 help complete
 help [[
 help for
Related Question