forked from PaulTaykalo/swift-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unused.sh
executable file
·37 lines (29 loc) · 1.13 KB
/
unused.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
#!/bin/zsh
start=$SECONDS
echo 'Gathering functions'
grep -rRh 'func [[:alnum:]]*' **/*.swift > raw_functions.txt
cat raw_functions.txt | grep -v '@IBAction' | grep -v ' override ' | grep -v 'func test' > filtered_functions.txt
cat filtered_functions.txt | grep -rRoh 'func [[:alnum:]]*' | sort | uniq | grep -o '[[:alnum:]]*$' > unique_functions.txt
FUNCTIONS_COUNT=`cat unique_functions.txt | wc -l`
echo "There are ${FUNCTIONS_COUNT} potential functions found"
echo "Gathering usage information"
cat unique_functions.txt | while read line
do
FOUND_ITEMS=`grep -r "$line" **/*.swift | wc -l`
if [ "1" -eq "$FOUND_ITEMS" ]; then
echo "$line $FOUND_ITEMS"
fi
done > usage.txt
FUNCTIONS_WIT_LOW_USAGE=`cat usage.txt | wc -l`
echo "There are ${FUNCTIONS_WIT_LOW_USAGE} potential functions to be deleted found"
cat usage.txt | sort -nk2 > sorted_usage.txt
echo "Gathering usage per each of them"
cat sorted_usage.txt | while read line
do
NAME=`echo $line | grep -o '[[:alnum:]]*'`
USAGES=`grep -rR -C 3 "$NAME" **/*.swift`
echo "---- $NAME ----"
echo "$USAGES"
echo ""
done > delete_me.txt
echo "It took $((SECONDS-start)) seconds."