-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-fetch
executable file
·31 lines (25 loc) · 1.24 KB
/
github-fetch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
# ensure args are passed
[ -z "$1" ] && echo -e "usage:\n\tgithub-fetch <author>/<repo> [--dmenu]" && exit 1
# seperate args into author/repo
author="$(echo "$1" | cut -d '/' -f1)"
repository="$(echo "$1" | cut -d '/' -f2)"
# buid the repository URL
repo_url="https://api.github.com/repos/${author}/${repository}/releases"
# determine the latest version
latest_version="$(curl -s "$repo_url" | grep browser_ | cut -d\" -f4 | head -n 1 | sed 's/.*'"$author"'\/'"$repository"'//' | cut -d '/' -f4)"
# allow for the use of dmenu for choosing file
if [ "$2" == "--dmenu" ]; then
file_url="$(curl -s "$repo_url" | grep browser_ | cut -d\" -f4 | grep $latest_version | dmenu -l 5)"
if [ ! -z "$file_url" ]; then
curl -L $file_url -o ${repository}-${latest_version}-$(echo $file_url | sed -r 's/.*\/([^/]+)$/\1/') || exit 1
exit 0
fi
echo "no selection made; download cancelled"
else
# if dmenu isn't being used, just download the latest version
echo "downloading version \"$latest_version\""
file_url="$(curl -s "$repo_url" | grep browser_ | cut -d\" -f4 | grep $latest_version | head -n 1)"
curl -L $file_url -o ${repository}-${latest_version}-$(echo $file_url | sed -r 's/.*\/([^/]+)$/\1/')
fi
# vim: syntax=sh