Skip to content

Conversation

@cho-m
Copy link
Member

@cho-m cho-m commented Dec 15, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

I was previously thinking of adding a separate method:

But I wasn't happy on naming as version number doesn't make much sense given the path will likely remain for v3, v4, etc as it is based on XDG.

This PR is a different idea for DSL of using an argument, with default to keep using compatdir path so all bash_completion.install usage remains the same.


This is needed as we recently enabled Click Bash completions

Which are incompatible with system Bash


One scenario that this does not automatically support is Bash 4 without bash-completion@2 installed. For now, users will need to manually adjust their Bash config file to load these.

We could adjust https://docs.brew.sh/Shell-Completion#configuring-completions-in-bash but it will make the logic more complicated to detect which Bash version is running and add multiple directories to load from.

Easier response to this scenario is to tell users to install bash-completion@2.

This directory can be used for Bash completions that need Bash >= 4 or
bash-completion >= 2. It is automatically searched by bash-completion.

Also make `:click` completions install into that directory.
Copilot AI review requested due to automatic review settings December 15, 2025 19:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for installing Bash completions to the modern XDG-based directory (share/bash-completion/completions) in addition to the legacy compatibility directory (etc/bash_completion.d). This is needed to support Click-based Bash completions which require Bash >= 4 or bash-completion >= 2, incompatible with the system Bash 3 on macOS.

Key changes:

  • Modified bash_completion method to accept an optional compat parameter (default: true)
  • Updated generate_completions_from_executable to automatically use the modern directory for Click-formatted completions
  • Added test coverage for the new functionality

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Library/Homebrew/formula.rb Added compat parameter to bash_completion method and integrated it with generate_completions_from_executable to support modern Bash completion directory
Library/Homebrew/test/formula_spec.rb Added test case to verify Click completions are installed to the modern directory while regular completions remain in the compat directory

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good! A few discussions around style/naming.


completion_script_path_map = {
bash: bash_completion/base_name,
bash: bash_completion(compat: shell_parameter_format != :click)/base_name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulling this into a variable with a comment would be nice; not clear why this is the case and a little hard to read the logic inline the method call

sig { returns(Pathname) }
def bash_completion = prefix/"etc/bash_completion.d"
sig { params(compat: T::Boolean).returns(Pathname) }
def bash_completion(compat: true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def bash_completion(compat: true)
def bash_completion(bash3: false)

maybe?

Copy link
Member Author

@cho-m cho-m Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had went with compat due to bash-completion naming, though I'm open to alternatives .

pkgconf bash-completion --variable compatdir --define-prefix
/opt/homebrew/etc/bash_completion.dpkgconf bash-completion --variable completionsdir --define-prefix
/opt/homebrew/share/bash-completion/completions

Some other ideas I was considering:

  • bash_completion(use_compatdir: false)
  • bash_completion(version = :v1), so bash_completion(:v2).install ...

If using bash3, it should also default to true to preserve existing behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants