-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_misc.sh
More file actions
executable file
·341 lines (318 loc) · 12.2 KB
/
Copy pathcustom_misc.sh
File metadata and controls
executable file
·341 lines (318 loc) · 12.2 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/env bash
#######################################
# this folder location
#######################################
function customBashExtensionsFolder(){
echo $(dirname "${BASH_SOURCE[0]}")
}
#######################################
# echo the command and run it
# example: echoAndRun ls some/folder/path
#######################################
function echoAndRun() {
echo "\$\$ $@" ;
eval "$@" ;
}
#######################################
# access the an online cheat sheet for the linux terminal
# example: cheat curl
#######################################
function cheat(){
echoAndRun "curl cheat.sh/$@"
}
#######################################
# composer update production
#######################################
function compup(){
composer update --no-dev
}
#######################################
# databases folder (~/Documents/Databases)
#######################################
alias dbsLocation='echo ~/Documents/Databases'
#######################################
# repositries folder (~/Documents/Repositories)
#######################################
alias repoLocation='echo ~/Documents/Repositories'
#######################################
# sites folder (~/Documents/Repositories/sites)
#######################################
alias sitesLocation='echo ~/Documents/Repositories/sites'
array=( $(dbsLocation) $(repoLocation) $(sitesLocation) )
for i in "${array[@]}"; do
#check folders exist
if [ ! -d ${i} ]; then
mkdir -p ${i} ;
fi
done
#######################################
# go to dbs folder
#######################################
function dbs(){
cd $(dbsLocation)
}
#######################################
# go to repositories folder
# example: repo myrepo
#######################################
function repo(){
cd $(repoLocation)/${1}
}
#######################################
# go to sites folder
# example: sites mysite
#######################################
function sites(){
cd $(sitesLocation)/${1}
}
#######################################
# connect to mysql using connectrion set in ./mysql-connection-details.txt
# It stops the warning shown when using "mysql -uroot -proot"
# "Warning: Using a password on the command line interface can be insecure."
#######################################
alias localMysqlConnection='mysql --defaults-extra-file=$(customBashExtensionsFolder)/mysql-connection-details.txt'
#######################################
# check if db exits
#######################################
function dbExists(){
if [ -z $1 ] || [ "$1" = "--help" ] ; then
echo 'check if database exits';
echo '';
echo 'arguments missing';
echo 'dbExists <<database name>>';
echo 'please try again';
return;
fi
local dbexists=$(localMysqlConnection -e "show databases like '${1}';")
if [ -z "${dbexists}" ]; then
echo 'false'
return 1
fi
echo 'true';
}
#######################################
# drop database
#######################################
function dropDb(){
if [ -z $1 ] || [ "$1" = "--help" ] ; then
echo 'drop database';
echo '';
echo 'arguments missing';
echo 'dropDb <<database name>>';
echo 'please try again';
return;
fi
local database dbexists continue
for database in "$@"; do
dbexists=$(localMysqlConnection -e "show databases like '${database}';")
if [ -z "${dbexists}" ]; then
echo "database ${1} not found"
return 1
fi
echo "\nare you sure you want to drop database ${database} ? [n]"
read continue
if [ -z "${continue}" ]; then
echo 'dropping database cancelled'
return 1
fi
if [ "${continue}" = "n" ]; then
echo 'dropping database cancelled'
return 1
fi
if [ "${continue}" = "N" ]; then
echo 'dropping database cancelled'
return 1
fi
echo "dropping database ${database}";
localMysqlConnection -e"drop database ${database};";
done
}
#######################################
# List the database tables ordered by size in mb
#######################################
function dbTablesSizes(){
if [ "$1" == "--help" ]; then
echo 'List the database tables ordered by size in mb'
echo 'dbTablesSizes'
echo 'dbTablesSizes << database>>'
fi
if [ -z $1 ]; then
localMysqlConnection -e '
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;'
else
localMysqlConnection -e '
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
Where table_schema = "'${1}'"
ORDER BY (data_length + index_length) DESC;'
fi
}
#######################################
# run php through a shell for xdebug
# example: phpDebug index.php
# requirements: php must be able to be run from the terminal with the command 'php'
#######################################
alias phpDebug="php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=On"
# turn on auto change directory. so dont have to type cd when changing directory
shopt -s autocd
#######################################
# open folder in nautilus
# example: open folder/name
# requirements: nautilus
#######################################
function open(){
nautilus ${1}
}
#######################################
# returns a lower case string of the arguments passed, with spaces replaced with _
#######################################
function safestring(){
local str
str="$*"
if [ "${str}" == "--help" ]; then
echo 'returns a lower case string of the arguments passed, with spaces replaced with _'
fi
str=${str,,} #lower case
echo "${str//[\:\;\-\. ]/_}" # replace white space and special characters
}
#######################################
# runs listCustomCommands
#######################################
alias listcustomcommands="listCustomCommands"
#######################################
# lists the custom commands. note prompt,git,docker,local,custom,laravel,mage1 or mage2 can be specified to filter only those commands
#######################################
function listCustomCommands(){
local DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "${1}" = "prompt" ] ; then
echo
grep function ${DIR}/gitprompt.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/gitprompt.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ' ;
echo
echo
elif [ "${1}" = "git" ] ; then
echo
grep function ${DIR}/gitextension.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/gitextension.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ' ;
echo
echo
elif [ "${1}" = "docker" ] ; then
echo
grep function ${DIR}/docker.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/docker.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ';
echo
echo
elif [ "${1}" = "local" ] ; then
echo
grep function ${DIR}/local_setup.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/local_setup.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ';
echo
echo
elif [ "${1}" = "custom" ] || [ "${1}" = "misc" ] ; then
echo
grep function ${DIR}/custom_misc.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/custom_misc.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ';
echo
echo
elif [ "${1}" = "laravel" ] ; then
echo
grep function ${DIR}/laravel.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/laravel.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ';
echo
echo
elif [ "${1}" = "mage1" ] || [ "${1}" = "magento1" ] ; then
echo
grep function ${DIR}/magento1.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/magento1.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ';
echo
echo
elif [ "${1}" = "mage2" ] || [ "${1}" = "magento2" ] ; then
echo
grep function ${DIR}/magento2.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/magento2.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ';
echo
echo
elif [ "${1}" = "personal" ] ; then
if [ -e ${DIR}/personal.sh ] ; then
echo
grep function ${DIR}/personal.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" | tr '\n' ' ';
grep alias ${DIR}/personal.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" | tr '\n' ' ';
echo
echo
fi
else
echo "-- Git Prompt --"
{ \
grep function ${DIR}/gitprompt.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/gitprompt.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
echo
echo
echo "-- Git --"
{ \
grep function ${DIR}/gitextension.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/gitextension.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
echo
echo
echo "-- Docker --"
{ \
grep function ${DIR}/docker.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/docker.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
echo
echo
echo "-- Local Setup --"
{ \
grep function ${DIR}/local_setup.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/local_setup.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
echo
echo
echo "-- Laravel --"
{ \
grep function ${DIR}/laravel.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/laravel.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
echo
echo
echo "-- Magento 1 --"
{ \
grep function ${DIR}/magento1.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/magento1.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
echo
echo
echo "-- Magento 2 --"
{ \
grep function ${DIR}/magento2.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/magento2.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
echo
echo
echo "-- Misc --"
{ \
grep function ${DIR}/custom_misc.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/custom_misc.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
if [ -e ${DIR}/personal.sh ] ; then \
echo
echo
echo "-- Personal --"
{ \
grep function ${DIR}/personal.sh | grep -v 'grep' | sed -e's/\s*function\s*//' | cut -f1 -d"(" ; \
grep alias ${DIR}/personal.sh | grep -v 'grep' | sed -e's/\s*alias\s*//' | cut -f1 -d"=" ; \
} | grep -i "${1}" | tr '\n' ' ';
fi ; \
echo
echo
fi
}