Omit aliases from completions#22352
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.
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.
|
This was harsh 😕 This change also omits user-defined aliases which is pretty inconvenient 😢 > __brew_list_aliases
list-depends list-installed-files list-installed-packages-by-date list-installed-packages-by-name list-installed-packages-versions list-upward-depends list-upward-depends-tree show whichTyping most of these verbatim is a burden now 😞 The linked discussion is two-people's opinion with zero thumb-ups and quite debatable grounding. And is actually about builtin aliases while this PR just dropped completion for aliases defined by users. Could this please be reverted or re-implemented to allow for user-defined aliases? |
And your response here is just one person's opinion. I agree with them that this was a good change which is why it was made.
Will review a PR for this for just user-defined aliases. |
The #18791 was specifically and only for user-defined aliases. |
|
@yermulnik beat you to it: #22693. Can you try that out and let me know if it's what you are expecting? |
|
Appreciate your time and effort ❤️ |
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.