-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
79 lines (65 loc) · 1.38 KB
/
pre-commit
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
#!/bin/sh
function containsSketchFile
{
declare -a argAry1=("${!1}")
for file in "${argAry1[@]}"; do
if [ "$file" = "$2" ];
then
return 0
fi
done
return 1
}
function mkdirForZipIfNeeded
{
arg="$1"
trimmed_arg="${arg%/*.sketch}"
if [ ! -d $trimmed_arg ];
then
mkdir -p $trimmed_arg
fi
}
IFS=';'
files=`git status --porcelain | grep "A " | grep .sketch`
files=${files//A /;} # replaces "A " with ;
files=${files//A /;} # catches "A " in case that happens
files=${files//\"/} # removes quotes around file names
files_array=($files)
array=()
for file in "${files_array[@]}";
do
trimmed_file=${file%/*}
if ! containsSketchFile array[@] $trimmed_file;
then
array+=($trimmed_file)
fi
done
files=`git status --porcelain | grep "M " | grep .sketch`
files=${files//M /;} # replaces "A " with ;
files=${files//M /;} # catches "M " in case that happens
files=${files//\"/} # removes quotes around file names
files_array=($files)
for file in "${files_array[@]}";
do
trimmed_file=${file%/*}
if ! containsSketchFile array[@] $trimmed_file;
then
array+=($trimmed_file)
fi
done
# echo "${array[@]}"
array_length=${#array[@]}
if ((array_length > 0))
then
if [ ! -d "zip" ];
then
mkdir "zip"
fi
for file in "${array[@]}";
do
mkdirForZipIfNeeded zip/${file}
zip -r "zip/${file}.zip" "./${file}"
done
git add zip
fi
exit 0