Skip to content

Instantly share code, notes, and snippets.

@NightMachinery
Forked from lukechilds/get_latest_release.sh
Last active April 17, 2021 13:15
Show Gist options
  • Save NightMachinery/3750f332b9237bf26ea58d82ef55d48c to your computer and use it in GitHub Desktop.
Save NightMachinery/3750f332b9237bf26ea58d82ef55d48c to your computer and use it in GitHub Desktop.
Shell - Get latest release from GitHub
## See latest version at https://github.com/NightMachinary/.shells/blob/master/scripts/zshlang/auto-load/others/github.zsh
## Usage:
# $ gh-release-get "creationix/nvm"
##
alias ec='print -r --'
function gh-release-get() {
local repo="$1"
local releases
releases="$(curl -s https://api.github.com/repos/"$repo"/releases)"
local tag
tag="$(ec "$releases" | jq -r ".[].tag_name" | gsort --version-sort --reverse | ghead -n 1)"
local assets
assets="$(ec $releases | jq -r --arg tag "$tag" '.[] | if .tag_name == $tag then .assets else empty end' )"
local desired
if [[ "$uname" == "Darwin" ]] ; then
desired="macos"
else
desired="ubuntu"
fi
local my_asset
my_asset="$(ec $assets | jq -r --arg desired "$desired" '.[] | select(.name | contains($desired)) | .browser_download_url')"
aria2c "$my_asset" # download asset
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment