Skip to content

Omit aliases from completions#22352

Merged
MikeMcQuaid merged 1 commit into
mainfrom
omit-alias-completions
May 20, 2026
Merged

Omit aliases from completions#22352
MikeMcQuaid merged 1 commit into
mainfrom
omit-alias-completions

Conversation

@MikeMcQuaid
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid commented May 20, 2026

Fixes https://github.com/orgs/Homebrew/discussions/6836

  • Avoid suggesting internal aliases because they duplicate canonical commands.
  • Keep alias expansion for option completion after users type an alias.
  • Regenerate bash, fish, zsh and internal command completion data.

  • 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? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes. Non-maintainers may only have one AI-assisted/generated PR open at a time.

OpenAI Codex 5.5 xhigh with manual review.


- Avoid suggesting internal aliases because they duplicate canonical commands.
- Keep alias expansion for option completion after users type an alias.
- Regenerate bash, fish, zsh and internal command completion data.
Copilot AI review requested due to automatic review settings May 20, 2026 12:37
Copy link
Copy Markdown
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 updates Homebrew’s shell completion generation to omit internal command aliases from top-level command suggestions (so users see canonical commands only), while still expanding internal aliases when the user types one so option/subcommand completion continues to work.

Changes:

  • Stop including internal command aliases in the cached/internal command lists used by completions.
  • Add internal-alias expansion hooks in bash/fish completions and adjust zsh generation to avoid emitting per-alias completion functions.
  • Add tests to ensure aliases are omitted from command suggestion lists but still expand correctly for completion dispatch.

Reviewed changes

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

Show a summary per file
File Description
Library/Homebrew/test/completions_spec.rb Adds expectations that bash/zsh/fish completion generation omits alias command suggestions but retains alias expansion for dispatch.
Library/Homebrew/test/commands_spec.rb Adds coverage ensuring rebuilt command lists don’t include internal aliases.
Library/Homebrew/completions/fish.erb Introduces alias expansion helper and filters out internal aliases from suggested commands.
Library/Homebrew/completions/bash.erb Filters alias commands from suggestions and expands internal aliases before dispatching to subcommand completion.
Library/Homebrew/completions.rb Generates completions from canonical command lists (no aliases) and injects alias-expansion data into templates.
Library/Homebrew/commands.rb Ensures rebuilt completion command lists omit internal aliases by default.
completions/zsh/_brew Regenerated zsh completion output without per-alias completion functions.
completions/internal_commands_list.txt Regenerated internal command list omitting internal alias entries.
completions/fish/brew.fish Regenerated fish completion output with alias expansion and alias omission in suggestions.
completions/bash/brew Regenerated bash completion output with alias expansion and alias omission in suggestions.
Comments suppressed due to low confidence (2)

Library/Homebrew/completions/bash.erb:165

  • __brew_list_aliases appears to be dead code now: it's defined but no longer referenced anywhere in the bash completion script (it used to be used by __brew_complete_commands). Consider removing this function (and the homebrew-aliases comment) to reduce generated completion size and avoid maintaining unused code.
# https://github.com/Homebrew/homebrew-aliases
__brew_list_aliases() {
  local aliases_dir="${HOME}/.brew-aliases"
  local pattern="^# alias: brew ([[:alnum:]-]+)$"
  local -a aliases

  [[ ! -d ${aliases_dir} ]] && return

  for file in "${aliases_dir}"/*; do
    [[ ! -f ${file} ]] && continue
    while read -r line; do
      if [[ ${line} =~ ${pattern} ]]; then
        aliases+=("${BASH_REMATCH[1]}")
        break
      fi
    done < "${file}"
  done
  [[ -n ${aliases[*]+"${aliases[*]}"} ]] && echo "${aliases[@]}"
}

completions/bash/brew:168

  • __brew_list_aliases is defined but not referenced anywhere in the generated bash completion file anymore. It looks like leftover code from when command completion appended homebrew-aliases entries; removing it would reduce file size and avoid carrying unused logic.
# https://github.com/Homebrew/homebrew-aliases
__brew_list_aliases() {
  local aliases_dir="${HOME}/.brew-aliases"
  local pattern="^# alias: brew ([[:alnum:]-]+)$"
  local -a aliases

  [[ ! -d ${aliases_dir} ]] && return

  for file in "${aliases_dir}"/*; do
    [[ ! -f ${file} ]] && continue
    while read -r line; do
      if [[ ${line} =~ ${pattern} ]]; then
        aliases+=("${BASH_REMATCH[1]}")
        break
      fi
    done < "${file}"
  done
  [[ -n ${aliases[*]+"${aliases[*]}"} ]] && echo "${aliases[@]}"
}

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

@MikeMcQuaid MikeMcQuaid enabled auto-merge May 20, 2026 13:48
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 7cc1b16 May 20, 2026
43 checks passed
@MikeMcQuaid MikeMcQuaid deleted the omit-alias-completions branch May 20, 2026 15:15
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