Homebrew获取水龙头中的公式列表

时间:2014-08-15 21:57:55

标签: homebrew

我如何(通过命令行)从自制软件中获取公式列表。
运行brew tap仅列出水龙头,但不列出该水龙头中存在的公式。

如果这样的命令不存在,我该如何以编程方式检索公式列表。

5 个答案:

答案 0 :(得分:7)

点击后:

TAP=telemachus/homebrew-desc  # (or whatever; need the homebrew- prefix)
TAP_PREFIX=$(brew --prefix)/Library/Taps
ls $TAP_PREFIX/$TAP/Formula/*.rb || ls $TAP_PREFIX/$TAP/*.rb

答案 1 :(得分:7)

点击中的公式列表显示在brew tap-info $TAP --json中。

从这里,您可以使用JSON命令行解析器提取列表,例如jq

例如,列出homebrew / cask-fonts和kde-mac / kde中的所有公式:

brew tap-info homebrew/cask-fonts kde-mac/kde --json | jq -r '.[]|(.formula_names[],.cask_tokens[])'

答案 2 :(得分:3)

Tim Smith答案的更新,其中包含Homebrew/路径中必要的(对我而言)TAP_PREFIX目录:

TAP=telemachus/homebrew-desc  # (or whatever; need the homebrew- prefix)
TAP_PREFIX=$(brew --prefix)/Homebrew/Library/Taps
ls $TAP_PREFIX/$TAP/Formula/*.rb 2>/dev/null || ls $TAP_PREFIX/$TAP/*.rb 2>/dev/null | xargs -I{} basename {} .rb

我还添加了将stderr重定向到/ dev / null,并在最后一行中删除除公式名称之外的所有名称。

答案 3 :(得分:0)

由于最近语法发生了变化,现在使用以下命令

export TAP=cloudfoundry/homebrew-tap
export TAP_PREFIX=$(brew --prefix)/Homebrew/Library/Taps
ls $TAP_PREFIX/$TAP/Formula/*.rb || ls $TAP_PREFIX/$TAP/*.rb
zsh: no matches found: /usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/Formula/*.rb
/usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/bbl.rb         /usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/cf-cli@6.rb
/usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/bbr.rb         /usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/cf-cli@7.rb
/usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/bosh-cli.rb    /usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/credhub-cli.rb
/usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/cf-cli.rb      /usr/local/Homebrew/Library/Taps/cloudfoundry/homebrew-tap/uaa-cli.rb

答案 4 :(得分:0)

改编自@cstork 对@forivall 回答的评论......

  1. 确保您已安装 jq
brew install jq
  1. 将以下函数添加到您的 .zshrc 或等效项(如 .bashrc
# Lists formulas from a given brew tap
# Call it with one or more taps to see their formulas
#   e.g.: brew-list-formulas tap/tap othertap/othertap
# Call it with no tap to list all taps
#   e.g.: brew-list-formulas
# Modified from https://stackoverflow.com/a/60607145/172272
function brew-list-formulas
{
  if (( $# == 0 )) then
    echo "Please specify one or more taps whose formulas you want listed.";
    echo "  e.g.: brew-list-formulas tap/tap othertap/othertap";
    echo "";
    echo "Available taps are:";
    echo "";
    brew tap;
  else
    echo "Formulas for tap(s) $* are:"
    echo "";
    brew tap-info --json "$@" | jq -r '.[]|(.formula_names[],.cask_tokens[])' | sort -V;
  fi
}
  1. 获取您的 .zshrc(或同等产品)
source ~/.zshrc
  1. 使用它!
> brew-list-formulas

Please specify one or more taps whose formulas you want listed.
  e.g.: brew-list-formulas tap/tap othertap/othertap

Available taps are:

clojure/tools
homebrew/cask
homebrew/cask-fonts
homebrew/core

> brew-list-formulas clojure/tools

Formulas for tap(s) clojure/tools are:

clojure/tools/clojure
clojure/tools/clojure@1.10.1.510
clojure/tools/clojure@1.10.1.524
clojure/tools/clojure@1.10.1.528