Bash completion script wrote to file under a directory when a file is expected in that location
I noticed after installing Ludus and opening a new bash shell that the bash script logic had created an error before I could even add the path to my .bashrc
for sourcing.
-bash: .: /home/ludus/.config/bash_completion: is a directory
We're getting that error because the bash_completion.sh (/etc/profile.d/bash_completion.sh
) script installed for bash by default is expecting $XDG_CONFIG_HOME/bash_completion
to be a file, not a directory.
I then realized that the path was also not the standard location where the bash-completion project searches:
Q. Where should I install my own local completions?
A. Put them in the completions subdir of $BASH_COMPLETION_USER_DIR (defaults to $XDG_DATA_HOME/bash-completion or ~/.local/share/bash-completion if $XDG_DATA_HOME is not set) to have them loaded automatically on demand when the respective command is being completed. See also the next question's answer for considerations for these files' names, they apply here as well. Alternatively, you can write them directly in ~/.bash_completion which is loaded eagerly by our main script.
Q. I author/maintain package X and would like to maintain my own completion code for this package. Where should I put it to be sure that interactive bash shells will find it and source it?
A. [ Disclaimer: Here, how to make the completion code visible to bash-completion is explained. We do not require always making the completion code visible to bash-completion. In what condition the completion code is installed should be determined at the author/maintainers' own discretion. ]
Install it in one of the directories pointed to by bash-completion's pkgconfig file variables. There are two alternatives:
The recommended directory is completionsdir, which you can get with pkg-config --variable=completionsdir bash-completion. From this directory, completions are automatically loaded on demand based on invoked commands' names, so be sure to name your completion file accordingly, and to include (for example) symbolic links in case the file provides completions for more than one command. The completion filename for command foo in this directory should be either foo, or foo.bash. (Underscore prefixed _foo works too, but is reserved for bash-completion internal use as a deprecation/fallback marker.) The other directory which is only present for backwards compatibility, its usage is no longer recommended, is compatdir (get it with pkg-config --variable=compatdir bash-completion). From this directory, files are loaded eagerly when bash_completion is loaded.
I will open a corresponding PR that makes the bash completion installation code more robust to resolve the error I encountered after running the Ludus installer script.