-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_repo.sh
executable file
·47 lines (40 loc) · 992 Bytes
/
setup_repo.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
#!/bin/bash
# Set default values for command line arguments
old_string="@nestjs-starter"
# Parse command line arguments
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-old|--old_string)
old_string="$2"
shift
shift
;;
-new|--new_string)
new_string="$2"
shift
shift
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done
# Check if the new string is provided
if [ -z "$new_string" ]
then
echo "Usage: ./script -new \"new_string\""
exit 1
fi
# Search for files containing the old string in the current directory and its subdirectories, excluding some dirs
files=$(grep -rlw --exclude-dir={node_modules,tmp,dist} --exclude={setup_repo.sh,README.md} "$old_string" .)
# Loop through the files and replace the old string with the new string
for file in $files
do
echo "processing file $file"
sed -i "" "s|$old_string|$new_string|g" "$file"
done
echo "Done"
# Thanks to chat-GPT for making this possible