forked from donnemartin/dev-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitrepo.sh
executable file
·76 lines (65 loc) · 1.79 KB
/
gitrepo.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /bin/bash
repo=""
zip=""
filter=""
tar=""
_usage="
Usage: gitrepo -r <repo author/repo name> [-f] <filter> [-z] [-t]
---
-r Repo owner/name (ie awesomeauthorsname/greatrepo)
-f Filter applied to the list of the repo's asset names.
If the filter doesn't match anything, none will be displayed
-z Download the zip file of the latest release
-t Download the tarball of the latest release
"
_prereqs="Script relies on Fzf for selection. Please install before continuing"
if [[ -z $(which fzf) ]]; then
echo $_prereqs
exit 2
fi
while getopts ":r:ftz:" o; do
case $o in
z)
zip="true"
;;
t)
tar="true"
;;
r)
repo=${OPTARG}
;;
f)
filter=${OPTARG}
;;
*)
echo $_usage
esac
done
if [[ -z $repo ]]; then
$_usage
fi
releases=$(curl -s https://api.github.com/repos/$repo/releases/latest)
assets_length=$(echo $releases | jq '.assets | length')
if [[ -n $zip ]]; then
wget $(echo $releases | jq -r '.zipball_url')
fi
if [[ -n $tar ]]; then
wget $(echo $releases | jq -r '.tarball_url')
fi
if [[ $assets_length -gt 0 ]]; then
if [[ -z $filter ]]; then
name=$(echo $releases | jq -r '.assets[] | .name' | fzf)
else
name=$(echo $releases | jq -r --arg filter "$filter" '.assets[] | select(.name | contains($filter)) | .name' | fzf)
fi
if [[ -n $name ]]; then
wget -q --show-progress --content-disposition $(echo $releases | jq -r --arg name "$name" '.assets[] | select(.name | contains($name)) | .browser_download_url')
exit 0
else
echo "No name specified. Canceling download"
exit 0
fi
else
echo "No assets available. Possibly only available as a tarball or zip file."
exit 0
fi