1
1
#! /bin/bash
2
2
3
3
current_project_name=" angular-boilerplate"
4
- current_git_provider=" github.com"
5
- current_git_provider_username =" juanmesa2097"
4
+ current_git_provider=" github.com/juanmesa2097 "
5
+ current_git_username =" juanmesa2097"
6
6
7
7
# Function to find files recursively
8
8
find_files () {
@@ -13,33 +13,40 @@ find_files() {
13
13
14
14
# Function to prompt for new project name
15
15
prompt_project_name () {
16
- read -rp " ▶ Enter new project name: " project_name
16
+ read -rp " ▶ Enter new project name: [current: $current_project_name ] " project_name
17
+ project_name=${project_name:- " $current_project_name " }
17
18
echo " $project_name "
18
19
}
19
20
20
- # Function to prompt for Git provider selection (Default: github.com)
21
+ # Function to prompt for Git provider
21
22
prompt_git_provider () {
22
- read -rp " ▶ Enter Git provider domain : [github.com ] " git_provider
23
- git_provider=${git_provider:- github.com }
23
+ read -rp " ▶ Enter Git provider: [current: $current_git_provider ] " git_provider
24
+ git_provider=${git_provider:- " $current_git_provider " }
24
25
echo " $git_provider "
25
26
}
26
27
27
- # Function to prompt for username
28
- prompt_git_provider_username () {
29
- read -rp " ▶ Enter the git provider username: " git_provider_username
30
- echo " $git_provider_username "
28
+ # Function to prompt for Git username
29
+ prompt_git_username () {
30
+ read -rp " ▶ Enter Git username: [current: $current_git_username ] " git_username
31
+ git_username=${git_username:- " $current_git_username " }
32
+ echo " $git_username "
31
33
}
32
34
33
35
# Function to prompt for confirmation (Default: n)
34
36
prompt_confirmation () {
35
37
local project_name=$1
36
38
local git_provider=$2
37
- local git_provider_username=$3
39
+ local git_username=$3
40
+
41
+ if [[ " $project_name " == " $current_project_name " && " $git_provider " == " $current_git_provider " && " $git_username " == " $current_git_username " ]]; then
42
+ echo " The parameters remained unchanged. No renaming and text replacement required." > /dev/tty
43
+ exit 0
44
+ fi
38
45
39
46
echo " You are about to rename the project with the following parameters:" > /dev/tty
40
47
echo " Project name:" " $project_name " > /dev/tty
41
48
echo " Git provider:" " $git_provider " > /dev/tty
42
- echo " Git provider username:" " $git_provider_username " > /dev/tty
49
+ echo " Git username:" " $git_username " > /dev/tty
43
50
read -rp " ▶ Are you sure you want to continue? (y/n): [n] " confirm
44
51
confirm=${confirm:- n}
45
52
echo " $confirm "
@@ -50,20 +57,20 @@ process_files() {
50
57
local files=$1
51
58
local project_name=$2
52
59
local git_provider=$3
53
- local git_provider_username =$4
60
+ local git_username =$4
54
61
55
62
for file in $files ; do
56
63
sed -i \
57
- -e " s/ $current_project_name / $project_name / g" \
58
- -e " s/ $current_git_provider / $git_provider / g" \
59
- -e " s/ $current_git_provider_username / $git_provider_username / g" \
64
+ -e " s| $current_git_provider | $git_provider | g" \
65
+ -e " s| $current_git_username | $git_username | g" \
66
+ -e " s| $current_project_name | $project_name | g" \
60
67
" $file "
61
68
done
62
69
63
70
echo
64
71
echo " ✅ Project renamed to $project_name "
65
72
echo " ✅ Git provider: $git_provider "
66
- echo " ✅ Git provider username: $git_provider_username "
73
+ echo " ✅ Git username: $git_username "
67
74
}
68
75
69
76
# Main script logic
76
83
77
84
project_name=$( prompt_project_name)
78
85
git_provider=$( prompt_git_provider)
79
- git_provider_username=$( prompt_git_provider_username)
80
- confirm=$( prompt_confirmation " $project_name " " $git_provider " " $git_provider_username " )
86
+ git_username=$( prompt_git_username)
87
+
88
+ confirm=$( prompt_confirmation " $project_name " " $git_provider " " $git_username " )
81
89
82
90
# Process files if confirmed
83
91
if [ " $confirm " == " y" ] || [ " $confirm " == " Y" ]; then
84
- process_files " $files " " $project_name " " $git_provider " " $git_provider_username "
92
+ process_files " $files " " $project_name " " $git_provider " " $git_username "
85
93
else
86
94
echo " ❌ Renaming and text replacement canceled."
87
95
fi
0 commit comments