【问题标题】:Homebrew get list of formulas in a tapHomebrew 在水龙头中获取公式列表
【发布时间】:2014-08-15 21:57:54
【问题描述】:

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

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

【问题讨论】:

    标签: homebrew


    【解决方案1】:

    点击中的公式列表在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[])'
    

    【讨论】:

    • 优秀的解决方案!谢谢! +1!
    • 我想知道为什么官方 brew 团队没有将类似的东西作为命令实现。我们可以向他们建议。也许像brew tap-info --list-formulas $TAP 这样的东西。
    • @rmbianchi 你可以随时提交拉取请求!当我自己研究这个问题时,我不得不将 cask_files 添加到 json 输出中,这被接受为 PR,然后维护人员在此基础上添加了 cask_tokens
    • 刚刚将function brew-tap-formulas { brew tap-info --json "$@" | jq -r '.[]|(.formula_names[],.cask_tokens[])' | sort -V } 添加到我的`~/.profile'。
    【解决方案2】:

    点击后:

    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
    

    【讨论】:

      【解决方案3】:

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

      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,并在最后一行中删除了除公式的专有名称之外的所有内容。

      【讨论】:

        【解决方案4】:

        改编自@ctork 对@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
        

        【讨论】:

          【解决方案5】:

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

          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
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2022-08-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多