-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-license
executable file
·55 lines (48 loc) · 1.32 KB
/
gen-license
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
#!/bin/sh
# generate a license
# requires fzf
name="$(git config --global user.name)"
year="$(date "+%Y")"
license_dir="${XDG_DATA_DIR}/licenses"
download_licenses() {
# Apache-2.0
wget -q "https://www.apache.org/licenses/LICENSE-2.0.txt" -O "${license_dir}/Apache-2.0"
# GPL-3.0
wget -q "https://mit-license.org/license.txt" -O "${license_dir}/GPL-3.0"
# MIT
wget -q "https://mit-license.org/license.txt" -O "${license_dir}/MIT"
}
format_apache2() {
sed -i "s/\[yyyy\]/${year}/; s/\[name of copyright owner\]/${name}/" "$1"
}
format_gpl3() {
head -- "${license_dir}/GPL-3.0" | sed "s/(C)/(C) ${year} ${name}/" >/tmp/GPL3.tmp
tail -n+10 -- "${license_dir}/GPL-3.0" >>/tmp/GPL3.tmp
mv -- /tmp/GPL3.tmp "$1"
}
format_mit() {
# FIX: name not inserting
sed -ir "s/[0-9]{4}/${year} ${name}/" "$1"
}
pick_license() {
if find "$license_dir" -prune -type d -empty | grep -q '^'; then
mkdir -p -- "${license_dir}"
download_licenses
fi
license="$(find "${license_dir}" -type f -printf "%f\n" | fzf +m --height=15%)"
case "$license" in
Apache-2.0)
cp -f -- "${license_dir}/${license}" ./LICENSE
format_apache2 "./LICENSE"
;;
GPL-3.0)
cp -f -- "${license_dir}/${license}" ./LICENSE
format_gpl3 "./LICENSE"
;;
MIT)
cp -f -- "${license_dir}/${license}" ./LICENSE
format_mit "./LICENSE"
;;
esac
}
pick_license