Subject: [bug#77181] [PATCH 0/5] gnu: Fix bash completion directories.

From: 45mg <[email-masked]>
Date: Sat, 22 Mar 2025 17:22:06 +0000

Hi Ian,

Ian Eure <[email-masked]> writes:

[...]
> The changes seem fine, but could you link to somewhere explaining 
> (or explain yourself) how bash completions are supposed to work? 
> In addition to /etc/bash_completions.d, I see many packages 
> installing them into /share/bash-completion.  Do both locations 
> work?  Do we need to move eveything into one or the other 
> location?

Here's a snippet from the bash-completion project's FAQ, explaining
this:
https://github.com/scop/bash-completion?tab=readme-ov-file#faq

--8<---------------cut here---------------start------------->8---
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.
--8<---------------cut here---------------end--------------->8---

On Guix, we have:

--8<---------------cut here---------------start------------->8---
# guix shell pkg-config bash-completion

[user@guix1 ]$ pkg-config --variable=completionsdir bash-completion
/gnu/store/5774mb64pqw93fpcchndiiq9fh80ngga-bash-completion-2.11/share/bash-completion/completions

[user@guix1 ]$ pkg-config --variable=compatdir bash-completion
/gnu/store/5774mb64pqw93fpcchndiiq9fh80ngga-bash-completion-2.11/etc/bash_completion.d
--8<---------------cut here---------------end--------------->8---

So, it looks like we should ideally be installing into
share/bash-completion/completions everywhere. etc/bash_completion.d will
also work, but the former is preferred because completions will be
loaded on-demand rather than eagerly. There are currently dozens of
packages using the latter; maybe some of them have a reason to
eager-load their completions.