diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 877b33c868..db63e649e5 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -172,6 +172,12 @@ case "$@" in source "${HOMEBREW_LIBRARY}/Homebrew/list.sh" homebrew-list "$@" && exit 0 ;; + # homebrew-tap only handles invocations with no arguments + tap) + source "${HOMEBREW_LIBRARY}/Homebrew/tap.sh" + homebrew-tap "$@" + exit 0 + ;; # falls back to cmd/help.rb on a non-zero return help | --help | -h | --usage | "-?" | "") homebrew-help "$@" && exit 0 diff --git a/Library/Homebrew/tap.sh b/Library/Homebrew/tap.sh new file mode 100644 index 0000000000..2a362a0eb3 --- /dev/null +++ b/Library/Homebrew/tap.sh @@ -0,0 +1,27 @@ +# Does the quickest output of brew tap possible for no arguments. +# HOMEBREW_LIBRARY is set by bin/brew +# shellcheck disable=SC2154 + +normalise_tap_name() { + local directory="$1" + local user + local repository + + user="$(tr '[:upper:]' '[:lower:]' <<<"${directory%%/*}")" + repository="$(tr '[:upper:]' '[:lower:]' <<<"${directory#*/}")" + repository="${repository#@(home|linux)brew-}" + echo "${user}/${repository}" +} + +homebrew-tap() { + local taplib="${HOMEBREW_LIBRARY}/Taps" + ( + shopt -s extglob + + for directory in "${taplib}"/*/* + do + [[ -d "${directory}" ]] || continue + normalise_tap_name "${directory#"${taplib}"/}" + done | sort + ) +}