dotconf/private_dot_config/private_mgmt/fns/github_latest.bash
2026-03-25 10:50:18 -05:00

18 lines
553 B
Bash

# shellcheck shell=bash
github_latest() {
repo="$1"
tag="${2:-latest}"
if [ "$tag" = "--no-latest-tag" ]; then
curl -sfSL "https://github.com/$repo/tags" \
| perl -ne 'm,a href="/'"$repo"'/releases/tag/v(\d\.\d(?:.\d)?)", && print "$1\n"' \
| sort -V \
| tail -n1 || echo "[github error]"
else
curl -sfSI "https://github.com/$repo/releases/$tag" \
| grep '^location' \
| awk -F/ '{print $NF}' \
| sed 's/\s\+$//' || echo "[github error]"
fi
}