-
-
Save NightMachinery/3750f332b9237bf26ea58d82ef55d48c to your computer and use it in GitHub Desktop.
Shell - Get latest release from GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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