Skip to content

Instantly share code, notes, and snippets.

@tennox
Last active January 21, 2022 04:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tennox/4688b07f3e3d65f15e98c66724216e16 to your computer and use it in GitHub Desktop.
Save tennox/4688b07f3e3d65f15e98c66724216e16 to your computer and use it in GitHub Desktop.
Github latest release download
# basic bash command
wget $(curl -s https://api.github.com/repos/filiph/linkcheck/releases/latest \
| jq -r '.assets | .[] | select(.name|contains("linux-x64.tar.gz")) | .browser_download_url')
function gh-latest -d "Download latest github release artifact"
argparse h/help 'o/output=' i/install -- $argv; or return
set -q _flag_h && echo 'Usage: gh-latest [-o/--output] [-o/--output] repo [matchRegex]' && return
set repo $argv[1]
set match $argv[2]
test -n "$match"; or set match 'amd64.deb$' # default value - which I often used
echo "Querying latest release for https://github.com/$repo"
set info (http https://api.github.com/repos/$repo/releases/latest)
set urls (echo $info | jq -r '.assets | .[] | select(.name|test("'$match'")) | .browser_download_url')
if test (count $urls) -ne 1 #TODO: open selector for >1
echo "Error: found "(count $urls)" matching:" >&2
if test (count $urls) -eq 0
echo $info | jq -r '.assets | .[] | .name' >&2
echo '| select(test("'$match'"))' >&2
else
printf '%s\n' $urls >&2
end
return 1
end
echo Downloading $urls[1]
if set -q _flag_i && not set -q _flag_o # when we should install, we need to know the name
set _flag_o (mktemp) # so - download to tempfile
end
http -bd --check-status (test -n "$_flag_o" && echo "-o$_flag_o") $urls[1]
if set -q _flag_i
sudo dpkg -i $_flag_o
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment