-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.sh
94 lines (83 loc) · 2.39 KB
/
clean.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
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
#!/bin/bash
# Fati Iseni
WorkingDir="$(pwd)"
########## Make sure you're not on a root path :)
safetyCheck()
{
declare -a arr=("" "/" "/c" "/d" "c:\\" "d:\\" "C:\\" "D:\\")
for i in "${arr[@]}"
do
if [ "$WorkingDir" = "$i" ]; then
echo "";
echo "You are on a root path. Please run the script from a given directory.";
exit 1;
fi
done
}
deleteBinObj()
{
echo "Deleting bin and obj directories...";
find "$WorkingDir/" -type d -name "bin" -exec rm -rf {} \; > /dev/null 2>&1;
find "$WorkingDir/" -type d -name "obj" -exec rm -rf {} \; > /dev/null 2>&1;
}
deleteVSDir()
{
echo "Deleting .vs directories...";
find "$WorkingDir/" -type d -name ".vs" -exec rm -rf {} \; > /dev/null 2>&1;
}
deleteLogs()
{
echo "Deleting Logs directories...";
find "$WorkingDir/" -type d -name "Logs" -exec rm -rf {} \; > /dev/null 2>&1;
}
deleteUserCsprojFiles()
{
echo "Deleting *.csproj.user files...";
find "$WorkingDir/" -type f -name "*.csproj.user" -exec rm -rf {} \; > /dev/null 2>&1;
}
deleteTestResults()
{
echo "Deleting test and coverage artifacts...";
find "$WorkingDir/" -type d -name "TestResults" -exec rm -rf {} \; > /dev/null 2>&1;
}
deleteLocalGitBranches()
{
echo "Deleting local unused git branches (e.g. no corresponding remote branch)...";
git fetch -p && git branch -vv | awk '/: gone\]/{print $1}' | xargs -I {} git branch -D {}
}
safetyCheck;
echo "";
if [ "$1" = "help" ]; then
echo "Usage:";
echo "";
echo -e "clean.sh [obj | vs | logs | user | coverages | branches | all]";
echo "";
echo -e "obj (Default)\t-\tDeletes bin and obj directories.";
echo -e "vs\t\t-\tDeletes .vs directories.";
echo -e "logs\t\t-\tDeletes Logs directories.";
echo -e "user\t\t-\tDeletes *.csproj.user files.";
echo -e "coverages\t-\tDeletes test and coverage artifacts.";
echo -e "branches\t-\tDeletes local unused git branches (e.g. no corresponding remote branch).";
echo -e "all\t\t-\tApply all options";
elif [ "$1" = "obj" ]; then
deleteBinObj;
elif [ "$1" = "vs" ]; then
deleteVSDir;
elif [ "$1" = "logs" ]; then
deleteLogs;
elif [ "$1" = "user" ]; then
deleteUserCsprojFiles;
elif [ "$1" = "coverages" ]; then
deleteTestResults;
elif [ "$1" = "branches" ]; then
deleteLocalGitBranches;
elif [ "$1" = "all" ]; then
deleteBinObj;
deleteVSDir;
deleteLogs;
deleteUserCsprojFiles;
deleteTestResults;
deleteLocalGitBranches;
else
deleteBinObj;
fi