-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_ini.sh
executable file
·74 lines (64 loc) · 2.02 KB
/
git_ini.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
#!/bin/bash
INITPATH="" # Absolute path to this project with / at the end
function create() {
### path = Project root directory of your projects, imported from constants
path=$(sed -n '9p' < ${INITPATH}constants.py | cut -d'"' -f 2)
USERNAME=""
### Goes to users homedirectory to create the new project there in subdirectory.
cd
mkdir -p $path
cd $path
### If remote repository variable is given, create a subdirectory for it.
if [[ "$2" == "gh" ]]
then
USERNAME=$(sed -n '1p' < ${INITPATH}constants.py | cut -d'"' -f 2)
mkdir -p GitHub
cd GitHub
elif [[ "$2" == "gl" ]]
then
USERNAME=$(sed -n '4p' < ${INITPATH}constants.py | cut -d'"' -f 2)
mkdir -p GitLab
cd GitLab
fi
mkdir $1
cd $1
PROJECTPATH="$(pwd)"
### Project Structure Creation ###
curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore
echo "# My Python Project" > "README.md"
touch __init__.py
touch requirements.txt
mkdir app
touch app/__init__.py
mkdir data
touch data/__init__.py
mkdir logs
touch logs/__init__.py
touch logs/error.log
mkdir test
touch test/__init__.py
### Create local git repository
git init
git add .
git commit -m "Initial commit"
### Create remote repository, if variable $2 is given
if [[ -z "$2" ]]
then
cd $INITPATH
python3 create.py $1 $2
cd ${PROJECTPATH}
fi
### If valid remote variable is given, project will be pushed to new created remote repository
if [[ "$2" == "gh" ]]
then
git remote add origin [email protected]:$USERNAME/$1.git
git push -u origin master
elif [[ "$2" == "gl" ]]
then
gitlab=$(sed -n '7p' < ${INITPATH}constants.py | cut -d'"' -f 2)
git remote add origin $gitlab$USERNAME/$1.git
git push -u origin master
fi
### Starts Visual Studio Code in the new created project directory if uncommented
# code . &
}