-
Notifications
You must be signed in to change notification settings - Fork 911
/
license.sh
executable file
·43 lines (36 loc) · 1.06 KB
/
license.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
#!/bin/bash
set -e
header_dir=$(dirname $0)/headers
tmpfile=$(mktemp)
trap "rm -f ${tmpfile}" EXIT
git diff --name-status main | awk '{print $NF}' | while read file; do
years=( $(git log --format='%ai' $file | cut -d- -f1 | sort -u) )
num_years=${#years[@]}
if [ "${num_years}" == 0 ]; then
export YEARS="$(date +%Y)"
else
yearA=${years[0]}
yearB=${years[$((${num_years}-1))]}
export YEARS="${yearA}-${yearB}"
fi
case "$file" in
vim25/{json,xml}/*)
# Ignore
;;
*.go)
sed -e "s/\${YEARS}/${YEARS}/" ${header_dir}/go.txt > ${tmpfile}
last_header_line=$(grep -n '\*/' ${file} | head -1 | cut -d: -f1)
tail -n +$((${last_header_line} + 1)) ${file} >> ${tmpfile}
mv ${tmpfile} ${file}
;;
*.rb)
sed -e "s/\${YEARS}/${YEARS}/" ${header_dir}/rb.txt > ${tmpfile}
last_header_line=$(grep -n '^$' ${file} | head -1 | cut -d: -f1)
tail -n +$((${last_header_line})) ${file} >> ${tmpfile}
mv ${tmpfile} ${file}
;;
*)
echo "Unhandled file: $file"
;;
esac
done