From c5253b23c2072c50997dfb5904b9d820ef91e526 Mon Sep 17 00:00:00 2001 From: Jamin Thornsberry Date: Wed, 20 Nov 2024 09:41:29 -0600 Subject: [PATCH] Remove fish command completions for excluded commands 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 Homebrew#10229. This makes `COMPLETIONS_EXCLUSION_LIST` the single source of truth for commands to exclude from completions. --- Library/Homebrew/completions.rb | 6 +++++- Library/Homebrew/completions/bash.erb | 5 ++--- Library/Homebrew/completions/fish.erb | 4 ++-- completions/bash/brew | 5 ++--- completions/fish/brew.fish | 7 ++----- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/completions.rb b/Library/Homebrew/completions.rb index 7b8a8d3f42..0780c48905 100644 --- a/Library/Homebrew/completions.rb +++ b/Library/Homebrew/completions.rb @@ -304,7 +304,11 @@ module Homebrew 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(/^-+/, "")}" diff --git a/Library/Homebrew/completions/bash.erb b/Library/Homebrew/completions/bash.erb index a9395d3ef3..4f782557ac 100644 --- a/Library/Homebrew/completions/bash.erb +++ b/Library/Homebrew/completions/bash.erb @@ -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 @@ -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} diff --git a/Library/Homebrew/completions/fish.erb b/Library/Homebrew/completions/fish.erb index 383966bb8c..1ec614d909 100644 --- a/Library/Homebrew/completions/fish.erb +++ b/Library/Homebrew/completions/fish.erb @@ -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 diff --git a/completions/bash/brew b/completions/bash/brew index fd983a54fb..1f46df99ad 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -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 @@ -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} diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index 400284aa51..a5643cd678 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -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 @@ -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`)' @@ -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' @@ -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'