Omit aliases from completions#22352
Merged
Merged
Conversation
- 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.
Contributor
There was a problem hiding this comment.
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_aliasesappears 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_aliasesis 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.
ZhongRuoyu
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes https://github.com/orgs/Homebrew/discussions/6836
brew lgtm(style, typechecking and tests) with your changes locally?OpenAI Codex 5.5 xhigh with manual review.