Ruoyu Zhong e9b158cd5c
Further simplify homebrew-tap calling
Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
2024-09-25 12:00:30 +08:00

29 lines
620 B
Bash

# 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 dir="$1"
local user
local repo
user="$(tr '[:upper:]' '[:lower:]' <<<"${dir%%/*}")"
repo="$(tr '[:upper:]' '[:lower:]' <<<"${dir#*/}")"
repo="${repo#@(home|linux)brew-}"
echo "${user}/${repo}"
}
homebrew-tap() {
local taplib="${HOMEBREW_LIBRARY}/Taps"
(
shopt -s extglob
for dir in "${taplib}"/*/*
do
[[ -d "${dir}" ]] || continue
dir="${dir#"${taplib}"/}"
normalise_tap_name "${dir}"
done | sort
)
}