Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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