You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过命令行获取Homebrew最新上传的x个软件包(formulae)?

获取Homebrew最近新增软件包的命令行方法

方法一:利用本地Homebrew仓库(推荐)

Homebrew默认已经在本地同步了homebrew-core仓库,直接用git命令就能提取最近新增的Formula,无需额外克隆仓库:

定义shell函数

把下面的函数添加到你的~/.zshrc或~/.bashrc配置文件中:

brew-new() {
  local count=${1:-10}  # 默认显示最近10个,可自定义数量
  local core_repo=$(brew --repository homebrew/core)
  
  cd "$core_repo" || exit 1
  git pull origin master > /dev/null 2>&1  # 先同步最新提交记录
  
  # 筛选出新增Formula文件的提交,提取纯净包名
  git log --diff-filter=A --pretty=format:"%s" -- Formula/ | grep -E "Formula/[a-z0-9-]+\.rb" | head -n "$count" | awk '{match($0, /Formula\/([a-z0-9-]+)\.rb/, m); print m[1]}'
}

使用方法

  1. 让配置生效:执行source ~/.zshrc(用bash的话替换为source ~/.bashrc)
  2. 默认看最近10个新包:brew-new
  3. 指定数量查看:比如看最近20个就执行brew-new 20

快速查看包详情

拿到包名后直接拼命令就能看功能,比如查看第一个新包的信息:

brew info $(brew-new 1)

方法二:通过GitHub API(无需依赖本地仓库)

如果不想操作本地仓库,可借助GitHub API结合jq工具解析提交数据:

前提

先安装jq:brew install jq

脚本示例

brew-new-api() {
  local count=${1:-10}
  # 从API拉取提交,筛选新增formula的提交并提取包名
  curl -s "https://api.github.com/repos/Homebrew/homebrew-core/commits?path=Formula/&per_page=$count" | jq -r '.[].commit.message | select(test("new formula:") or test("Added formula for")) | split(" ")[-1]'
}

使用方法

  • 默认看最近10个:brew-new-api
  • 指定数量:brew-new-api 15

注意:GitHub API对未认证用户有每小时60次的请求限制,日常使用完全足够。

内容的提问来源于stack exchange,提问作者Dr Krishnakumar Gopalakrishnan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 05:52:43