forked from jessfraz/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.dutils
More file actions
228 lines (179 loc) · 3.75 KB
/
.dutils
File metadata and controls
228 lines (179 loc) · 3.75 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
#! PROJECTS CONFIG LOADER - dont touch it, bitch. Keep moving.
#
#
projects_dir="$HOME/.projects"
curr_file="$projects_dir/.curr"
if [ ! -d $projects_dir ]; then
mkdir ${projects_dir}
fi
if [ ! -f $curr_file ]; then
touch $curr_file
fi
function curr() {
cat $curr_file
}
function set_curr() {
if [ ! -f "${projects_dir}/${@}" ]; then
echo "project named \""$@"\" not found"
return
fi
rm $curr_file || echo "no previous curr set up"
echo "$@" >$curr_file
echo "current project context set up to $(curr)"
load_curr
}
function load_curr() {
curr_project="${projects_dir}/$(curr)"
source $curr_project
source ${PROJECT_DIR}/.env 2>/dev/null
}
load_curr 2>/dev/null
function confirm() {
# call with a prompt string or use a default
read -r -p "Are you sure? [y/N]: " response
case "$response" in
[yY][eE][sS] | [yY])
return 1
;;
*)
return 0
;;
esac
}
function add_project() {
project_name="$@"
echo "you are going to add the project named \"$project_name\" as one linked to $(pwd)"
confirmed=$(confirm)
echo $confirmed
if [ $confirmed ]; then
return
fi
read -r -p "main service name (e.g: web): " service_name
project_file="${projects_dir}/${project_name}"
echo "PROJECT_DIR=$(pwd)" >>$project_file
echo "PROJECT_SERVICE_NAME=${service_name}" >>$project_file
echo "saved project named $project_name with service named $service_name"
set_curr $project_name
load_curr
}
function dcd() {
cd ${PROJECT_DIR}
}
function on_project() {
(dcd && "$@")
}
function compose_project_name() {
echo ${COMPOSE_PROJECT_NAME-$PROJECT_DIR}
}
#! DOCKER AND COMPOSE ENTRYPOINTS
#
#
function entrypoint() {
on_project docker-compose "$@"
}
function up() {
entrypoint up "$@"
}
function build() {
entrypoint build "$@"
}
function down() {
entrypoint down "$@"
}
function dps() {
entrypoint ps "$@"
}
function dps_svc() {
dps "$@" $PROJECT_SERVICE_NAME
}
function exec() {
entrypoint exec $PROJECT_SERVICE_NAME "$@"
}
function run_rm() {
entrypoint run --rm $PROJECT_SERVICE_NAME "$@"
}
function run() {
if [ "$(dps_svc -q)" = "" ]; then
run_rm "$@"
else
exec "$@"
fi
}
function update(){
curl "https://gitlab.web-experto.com.ar/sebach1/dutils/raw/master/_" > "$HOME/.dutils"
}
function multiline() {
run sh -c "$@"
}
#! RAILS
#
#
##? BUNDLE
#
function dbundle() {
run bundle "$@"
}
function bundle_install() {
dbundle install --jobs=20 --retry=2 --quiet
build ${PROJECT_SERVICE_NAME}
}
function bundle_exec() {
dbundle exec "$@"
}
function bundle_add() {
dbundle add "$@" --skip-install
bundle_install
}
function bundle_update() {
dbundle update --source "$@"
build ${PROJECT_SERVICE_NAME}
}
##? UTILS
#
function migrate() {
multiline 'bundle exec rails db:migrate || bundle exec rails db:migrate:reset'
}
function help(){
cat $projects_dir/README.md
}
#! NPM
#
#
function dnpm() {
run npm "$@"
}
function npm_run() {
dnpm run "$@"
}
function npm_update() {
dnpm update "$@"
build ${PROJECT_SERVICE_NAME}
}
function npm_install() {
dnpm install "$@"
build ${PROJECT_SERVICE_NAME}
}
alias npmi=npm_install
#! SETUP
#
#
function setup() {
if [ "$(compose_project_name)" = "cereales" ]; then
setup_cereales "$@"
fi
}
function setup_cereales() {
down
if [ "$PROJECT_SERVICE_NAME" = "backend" ]; then
setup_cereales_backend "$@"
elif [ "$PROJECT_SERVICE_NAME" = "frontend" ]; then
setup_cereales_frontend "$@"
fi
}
function setup_cereales_backend() {
bundle_exec rails db:setup
}
function setup_cereales_frontend() {
echo "not implemented"
}