Skip to content

Commit

Permalink
Remove fish command completions for excluded commands
Browse files Browse the repository at this point in the history
This removes fish command completions (but keeps argument completions)
for commands in the `COMPLETIONS_EXCLUSION_LIST` list.

It also removes unnecessary exclusions of `*instal` aliases in command
suggestions in bash and fish completions, since those were removed from
`internal_commands_list.txt` in #10229. This makes
`COMPLETIONS_EXCLUSION_LIST` the single source of truth for commands to
exclude from completions.
  • Loading branch information
jaminthorns committed Nov 20, 2024
1 parent 0b25b5c commit c5253b2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Library/Homebrew/completions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ def self.generate_fish_subcommand_completion(command)
return unless command_gets_completions? command

command_description = format_description Commands.command_description(command, short: true), fish: true
lines = ["__fish_brew_complete_cmd '#{command}' '#{command_description}'"]
lines = if COMPLETIONS_EXCLUSION_LIST.include?(command)
[]
else
["__fish_brew_complete_cmd '#{command}' '#{command_description}'"]
end

options = command_options(command).sort.filter_map do |opt, desc|
arg_line = "__fish_brew_complete_arg '#{command}' -l #{opt.sub(/^-+/, "")}"
Expand Down
5 changes: 2 additions & 3 deletions Library/Homebrew/completions/bash.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ __brew_complete_tapped() {

__brew_complete_commands() {
# Auto-complete Homebrew commands
# Do NOT auto-complete "*instal" aliases for "*install" commands

local cur="${COMP_WORDS[COMP_CWORD]}"
local cmds
Expand All @@ -118,10 +117,10 @@ __brew_complete_commands() {
cmds=${__HOMEBREW_COMMANDS}
elif [[ -n ${HOMEBREW_CACHE:-} && -f ${HOMEBREW_CACHE}/all_commands_list.txt ]]
then
cmds="$(< "${HOMEBREW_CACHE}/all_commands_list.txt" \grep -v instal$)"
cmds="$(< "${HOMEBREW_CACHE}/all_commands_list.txt")"
elif [[ -n ${HOMEBREW_REPOSITORY:-} && -f ${HOMEBREW_REPOSITORY}/completions/internal_commands_list.txt ]]
then
cmds="$(< "${HOMEBREW_REPOSITORY}/completions/internal_commands_list.txt" \grep -v instal$)"
cmds="$(< "${HOMEBREW_REPOSITORY}/completions/internal_commands_list.txt")"
fi
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${cmds}" -- "${cur}")
export __HOMEBREW_COMMANDS=${cmds}
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/completions/fish.erb
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ end

function __fish_brew_suggest_commands -d "Lists all commands names, including aliases"
if test -f (brew --cache)/all_commands_list.txt
cat (brew --cache)/all_commands_list.txt | \grep -v instal\$
cat (brew --cache)/all_commands_list.txt
else
cat (brew --repo)/completions/internal_commands_list.txt | \grep -v instal\$
cat (brew --repo)/completions/internal_commands_list.txt
end
end

Expand Down
5 changes: 2 additions & 3 deletions completions/bash/brew
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ __brew_complete_tapped() {

__brew_complete_commands() {
# Auto-complete Homebrew commands
# Do NOT auto-complete "*instal" aliases for "*install" commands

local cur="${COMP_WORDS[COMP_CWORD]}"
local cmds
Expand All @@ -105,10 +104,10 @@ __brew_complete_commands() {
cmds=${__HOMEBREW_COMMANDS}
elif [[ -n ${HOMEBREW_CACHE:-} && -f ${HOMEBREW_CACHE}/all_commands_list.txt ]]
then
cmds="$(< "${HOMEBREW_CACHE}/all_commands_list.txt" \grep -v instal$)"
cmds="$(< "${HOMEBREW_CACHE}/all_commands_list.txt")"
elif [[ -n ${HOMEBREW_REPOSITORY:-} && -f ${HOMEBREW_REPOSITORY}/completions/internal_commands_list.txt ]]
then
cmds="$(< "${HOMEBREW_REPOSITORY}/completions/internal_commands_list.txt" \grep -v instal$)"
cmds="$(< "${HOMEBREW_REPOSITORY}/completions/internal_commands_list.txt")"
fi
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${cmds}" -- "${cur}")
export __HOMEBREW_COMMANDS=${cmds}
Expand Down
7 changes: 2 additions & 5 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ end

function __fish_brew_suggest_commands -d "Lists all commands names, including aliases"
if test -f (brew --cache)/all_commands_list.txt
cat (brew --cache)/all_commands_list.txt | \grep -v instal\$
cat (brew --cache)/all_commands_list.txt
else
cat (brew --repo)/completions/internal_commands_list.txt | \grep -v instal\$
cat (brew --repo)/completions/internal_commands_list.txt
end
end

Expand Down Expand Up @@ -867,7 +867,6 @@ __fish_brew_complete_arg 'info; and not __fish_seen_argument -l cask -l casks' -
__fish_brew_complete_arg 'info; and not __fish_seen_argument -l formula -l formulae' -a '(__fish_brew_suggest_casks_all)'


__fish_brew_complete_cmd 'instal' 'Install a formula or cask'
__fish_brew_complete_arg 'instal' -l HEAD -d 'If formula defines it, install the HEAD version, aka. main, trunk, unstable, master'
__fish_brew_complete_arg 'instal' -l adopt -d 'Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`'
__fish_brew_complete_arg 'instal' -l appdir -d 'Target location for Applications (default: `/Applications`)'
Expand Down Expand Up @@ -1612,7 +1611,6 @@ __fish_brew_complete_arg 'unbottled' -l verbose -d 'Make some output more verbos
__fish_brew_complete_arg 'unbottled' -a '(__fish_brew_suggest_formulae_all)'


__fish_brew_complete_cmd 'uninstal' 'Uninstall a formula or cask'
__fish_brew_complete_arg 'uninstal' -l cask -d 'Treat all named arguments as casks'
__fish_brew_complete_arg 'uninstal' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'uninstal' -l force -d 'Delete all installed versions of formula. Uninstall even if cask is not installed, overwrite existing files and ignore errors when removing files'
Expand Down Expand Up @@ -1728,7 +1726,6 @@ __fish_brew_complete_arg 'update-python-resources' -l version -d 'Use the specif
__fish_brew_complete_arg 'update-python-resources' -a '(__fish_brew_suggest_formulae_all)'


__fish_brew_complete_cmd 'update-report' 'The Ruby implementation of `brew update`'
__fish_brew_complete_arg 'update-report' -l auto-update -d 'Run in \'auto-update\' mode (faster, less output)'
__fish_brew_complete_arg 'update-report' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'update-report' -l force -d 'Treat installed and updated formulae as if they are from the same taps and migrate them anyway'
Expand Down

0 comments on commit c5253b2

Please sign in to comment.