forked from simonwhitaker/gibo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dobo
executable file
·164 lines (143 loc) · 3.64 KB
/
dobo
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
#
# Script for easily accessing .dockerignore boilerplates from
# https://github.com/KeisukeYamashita/dockerignore
readonly remote_repo=https://github.com/KeisukeYamashita/dockerignore.git
readonly local_repo=${DOBO_BOILERPLATES:-"$HOME/.dockerignore-boilerplates"}
readonly current_repo_rev=$(cd "${local_repo}" 2>/dev/null && git rev-parse HEAD)
readonly remote_web_root="https://raw.github.com/KeisukeYamashita/dobo/${current_repo_rev}"
version() {
echo "$(basename "$0") 1.0.0 by KeisukeYamashita <[email protected]>"
echo "https://github.com/KeisukeYamashita/dobo"
}
usage() {
version
cat << EOF >&2
Fetches dockerignore boilerplates from https://github.com/KeisukeYamashita/dockerignore
Usage:
$(basename "$0") [command]
Example:
$(basename "$0") dump Swift Xcode >> .dockerignore
Commands:
dump BOILERPLATE... Write boilerplate(s) to STDOUT
help Display this help text
list List available boilerplates
root Show the directory where dobo stores its boilerplates
search STR Search for boilerplates with STR in the name
update Update list of available boilerplates
version Display current script version
EOF
}
clone() {
if [ "$1" ] && [ "$1" = '--silently' ]; then
git clone -q "${remote_repo}" "${local_repo}"
else
echo "Cloning ${remote_repo} to ${local_repo}"
git clone "${remote_repo}" "${local_repo}"
fi
}
init() {
if [ ! -e "${local_repo}/.git" ]; then
clone "${1}"
fi
}
list() {
init
if [ -t 1 ]; then
shape='column'
else
shape='cat'
fi
find "${local_repo}" -name '*.dockerignore' | sort -f \
| sed -e 's@^.*/\([^/]*\)\.dockerignore$@\1@' | eval ${shape}
}
root() {
echo "${local_repo}"
}
search() {
init --silently
for filename in $(find "${local_repo}" -iname "*$**.dockerignore" -exec basename \{\} .dockerignore \; | sort); do
echo "$filename"
done
}
update() {
if [ ! -e "${local_repo}/.git" ]; then
clone
else
cd "${local_repo}" || exit
git pull --ff origin master
fi
}
dump() {
init --silently
language_file=$(find "${local_repo}" -iname "$1.dockerignore" | head -n 1)
language_file_relative=${language_file#"${local_repo}/"}
if [ -n "$language_file" ]; then
echo "### $remote_web_root/$language_file_relative"
echo
cat "$language_file"
echo
echo
else
echo "Unknown argument: $1" >&2
exit 1
fi
}
# --- Main entry point ----------------------
if [ $# -eq 0 ]; then
usage
exit 1
fi
# Parse comand-line
should_dump=0
while [ $# -gt 0 ]; do
case $1 in
version )
version
exit 0
;;
list )
list
exit 0
;;
root )
root
exit 0
;;
update )
update
exit 0
;;
help )
usage
exit 0
;;
dump )
if [ $# -gt 1 ]; then
should_dump=1
else
usage
exit 1
fi
;;
search )
if [ $# -gt 1 ]; then
shift
search "$@"
exit 0
else
usage
exit 1
fi
;;
* ) # default case
if [ $should_dump -eq 1 ]; then
dump "$1"
else
usage
exit 1
fi
;;
esac
shift
done