-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
139 lines (123 loc) · 4.09 KB
/
.bashrc
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Open .bashrc in editor
alias bashrc="start $HOME/.bashrc"
DEFAULT_PASSWORD="1234"
# Colors
Reset=`tput sgr0`
# Text Colors
ErrorText=`tput setaf 1`
SuccessText=`tput setaf 2`
WarningText=`tput setaf 3`
InfoText=`tput setaf 4`
# Background Colors
GreenBg=`tput setaf 16 && tput setab 2`
# Help
dj(){
printf "\n${GreenBg}[List of Commands]${Reset}\n"
printf "%-35s %s\n" "${SuccessText}dj-admin [USER_NAME]${Reset}" "creates custom superuser or by USER_NAME and DEFAULT_PASSWORD"
printf "%-35s %s\n" "${SuccessText}dj-app APP_NAME${Reset}" "creates a new app by APP_NAME"
printf "%-35s %s\n" "${SuccessText}dj-cleaner${Reset}" "recreates database"
printf "%-35s %s\n" "${SuccessText}dj-env [ENVIROMENT_DIR]${Reset}" "activates current project environment or ENVIROMENT_DIR"
printf "%-35s %s\n" "${SuccessText}dj-mig [APP_NAME]${Reset}" "makes migrations for project or specific APP_NAME"
printf "%-35s %s\n" "${SuccessText}dj-mkenv [ENVIROMENT_NAME]${Reset}" "creates environment as env or ENVIROMENT_NAME"
printf "%-35s %s\n" "${SuccessText}dj-pip [PACKAGE_NAME]${Reset}" "installs python package by PACKAGE_NAME"
printf "%-35s %s\n" "${SuccessText}dj-project [PROJECT_NAME]${Reset}" "creates a new project as config"
printf "%-35s %s\n" "${SuccessText}dj-req${Reset}" "updates requirements.txt"
printf "%-35s %s\n" "${SuccessText}dj-run${Reset}" "runs django project on server"
printf "%-35s %s\n" "${SuccessText}dj-shell${Reset}" "opens django project shell"
printf "%-35s %s\n" "${SuccessText}dj-upg PACKAGE_NAME${Reset}" "upgrades python package by PACKAGE_NAME"
printf "%-35s %s\n" "${SuccessText}dj-user USER_NAME${Reset}" "creates user by USER_NAME and DEFAULT_PASSWORD"
}
# ACTIVE DJANGO ENVIRONMENT
dj-env(){
echo "${SuccessText}Activating Virtual Environment ...${Reset}"
if [ -z "$1" ]
then
ENV_DIR=$(find ../env_* -maxdepth 0 -type d)
source ${ENV_DIR}/Scripts/activate
else
source "$1"/Scripts/activate
fi
}
# CREATE DJANGO ENVIRONMENT
dj-mkenv(){
echo "${SuccessText}Creating Virtual Environment ...${Reset}"
if [ -z "$1" ]
then
python -m venv env && dj-env env
else
python -m venv "$1" && dj-env "$1"
fi
dj-upg pip
}
# CREATE DJANGO PROJECT
dj-project(){
if [ -z "$1" ]
then
django-admin startproject config
else
django-admin startproject config && python mv config/ "$1"/
fi
}
# CREATE DJANGO APP
dj-app(){
if [ -z "$1" ]
then
echo "${WarningText}run command with APP_NAME${Reset}"
else
python manage.py startapp "$1"
fi
}
# INSTALL PYTHON PACKAGE
dj-pip(){
if [ -z "$1" ]
then
python -m pip install -r requirements.txt
else
python -m pip install "$1"
fi
}
# UPGRADE PYTHON PACKAGE
dj-upg(){
python -m pip install "$1" --upgrade
}
# DO DJANGO MIGRATION
dj-mig(){
if [ -z "$1" ]
then
python manage.py makemigrations && python manage.py migrate
else
python manage.py makemigrations "$1" && python manage.py migrate "$1"
fi
}
# CREATE SIMPLE USER
dj-user(){
if [ -z "$1" ]
then
echo "${WarningText}run command with USER_NAME${Reset}"
else
python manage.py shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_user('"$1"', '"$1"@mail.com', '${DEFAULT_PASSWORD}')"
fi
}
# CREATE SUPERUSER
dj-admin(){
if [ -z "$1" ]
then
python manage.py createsuperuser
else
python manage.py shell -c "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('"$1"', '"$1"@mail.com', '${DEFAULT_PASSWORD}')"
fi
}
# CLEAN DATABASE
dj-cleaner(){
rm -rf db.sqlite3
find . -path "*/migrations/*.pyc" -delete
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
python manage.py makemigrations
python manage.py migrate
}
# DJANGO SHELL
alias dj-shell="python manage.py shell"
# RUN DJANGO PROJECT
alias dj-run="python manage.py runserver"
# UPDATE REQUIREMENTS
alias dj-req="python -m pip freeze > requirements.txt"