-
Notifications
You must be signed in to change notification settings - Fork 0
/
.scripts
393 lines (342 loc) · 9.79 KB
/
.scripts
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
## Python
_runCelery() {
app=$1
virtualenv=$2
use_redis=$3
if [ "$app" = "-" ]; then
app="core"
fi
if [ "$virtualenv" != "" ]; then
virtualenv="py-act ${virtualenv};"
fi
if [ "$use_redis" != "y" ]; then
ttab "rabbitmq-server"
ttab "sleep 10; $virtualenv celery -A $app worker --beat -l INFO"
ttab "sleep 15; $virtualenv celery -A $app flower"
else
ttab "$virtualenv celery -A $app worker --beat -l INFO"
ttab "sleep 10; $virtualenv celery -A $app flower"
fi
}
### Django
_django_commands() {
_show_help() {
echo "TODO"
}
command=$1
if [ "$command" = "" ]; then
_show_help
elif [ "$command" = "serve" ]; then
python manage.py runserver "${@:2}"
elif [ "$command" = "migrate" ]; then
python manage.py migrate "${@:2}"
elif [ "$command" = "migrate:fresh" ]; then
python manage.py migratefresh "${@:2}"
elif [ "$command" = "migrate:refresh" ]; then
python manage.py migraterefresh "${@:2}"
elif [ "$command" = "napp" ]; then
python manage.py startapp "${@:2}"
elif [ "$command" = "shell" ]; then
python manage.py shell "${@:2}"
elif [ "$command" = "migrate:revert" ]; then
if [ "$2" != "" ]; then
python manage.py migrate $2 zero
else
python manage.py migrate zero
fi
elif [ "$command" = "--help" ]; then
_show_help
else
echo "Command not available."
return 1
fi
}
## PHP
_runPHPServer() {
if [ "$1" = "" ]; then
php -S localhost:8000
elif [ "$1" = "public" ]; then
php -S localhost:8000 -t public
else
php -S localhost:$1 -t $2
fi
}
_composerCheat() {
cmd=$1
if [ "$cmd" = "i" ]; then
composer install
elif [ "$cmd" = "u" ]; then
composer update
elif [ "$cmd" = "da" ]; then
composer dump-autoload
elif [ "$cmd" = "su" ]; then
sudo composer self-update
fi
}
## Mysql
_mysqlImportDB() {
# $1 => Database Name
# $2 => SQL Path
mysql -u root -p $1 < $2
}
_mysqlDropCreate() {
mysqladmin -u root -p drop $1
mysqladmin -u root -p create $1
}
## Git
_gitCommitCount() {
branch=$1
if [ "$branch" = "" ]; then
git rev-list HEAD --count
else
git rev-list $branch --count
fi
}
## Stop Specific Port
_killPort() {
sudo kill $(sudo lsof -t -i:$1) > /dev/null 2>&1
echo "Port $1 has been Terminated!"
}
## Run Ngrok
_runngrok() {
domain=$1
port=$2
if [ "$domain" = "" ]; then
echo "Please specify the tunnel domain!"
return 1
else
if [ "$2" = "" ]; then
port=8000
echo "Using default port 8000"
fi
$INSTALL_HOME/ngrok http -bind-tls=true -subdomain=$domain $port
fi
}
## Terminal
_cheatsheet() {
echo "Terms"
echo "-> AL : Arrow Left"
echo "-> ^ : Shift\n"
echo "== Terminal =="
echo "Jump to Beginning of Line: CTRL+A / fn+AL"
echo "Jump to End of Line: CTRL+E"
echo "Go to Next Line: CTRL+N"
echo "Go to Previous Line: CTRL+P"
echo "Delete Previous Word: CTRL+W"
echo "Delete Line from Cursor to Beginning: CTRL+U"
echo "Delete Line from Cursor to End: CTRL+K\n"
echo "== GIT =="
echo "Diff with last commit: git diff HEAD^ HEAD\n"
echo "== Intellij =="
echo "Select next occurence: CTRL+G"
echo "Close current tab: CTRL+W"
echo "== Atom =="
echo "Select every beginning of line: CMD+^+L"
}
_searchFileInFolder() {
_path=$1
_filename=$2
if [ "$_path" = "" ]; then
echo "Please specify the search path!"
return 1
elif [ "$_filename" = "" ]; then
echo "Please specify the filename to search!"
return 1
fi
if [ -d "$_path" ]; then
find $_path -type f 2>/dev/null | grep "$_filename"
else
echo "The path should be a directory!"
return 1
fi
}
_imageTools() {
command=$1
result_name=`uuidgen`
# Documentation: https://imagemagick.org/script/command-line-processing.php
if [ "$command" = "compress" ]; then
magick mogrify -resize 60% *
else
echo "Image Tools with key '$command' not available!\n"
return 1
fi
}
_videoTools() {
command=$1
result_name=`uuidgen`
if [ "$command" = "compress" ]; then
# -b:v ==> bitrate video
# -b:a ==> bitrate audio
ffmpeg -i $2 -c:v libx264 -b:v 1.5M -c:a aac -b:a 128k ~/Desktop/video-${result_name}.mp4
if [ $? -eq 0 ]; then
echo "Video saved to ~/Desktop/video-${result_name}.mp4"
fi
elif [ "$command" = "trim" ]; then
ffmpeg -i $2 -ss $3 -t $4 -async 1 -max_muxing_queue_size 9999 ~/Desktop/video-${result_name}.mp4
if [ $? -eq 0 ]; then
echo "Video saved to ~/Desktop/video-${result_name}.mp4"
fi
elif [ "$command" = "convert" ]; then
if [ "$2" == "" ]; then
echo "Please specify a video!"
return 1
fi
ffmpeg -i $2 -vcodec libx264 -acodec aac ~/Desktop/video-${result_name}.mp4
if [ $? -eq 0 ]; then
echo "Video saved to ~/Desktop/video-${result_name}.mp4"
fi
else
echo "Video Tools with key '$command' not available!\n"
return 1
fi
}
## C++
_compileCpp() {
file=$1
c11=$2
f_name=`echo $file | cut -d'.' -f1`
if [ "$c11" = "" ]; then
g++ $file -o $f_name
elif [ "$c11" = "y" ]; then
g++ -std=c++11 $file -o $f_name
fi
}
## Docker
_runDocker() {
alias=$1
if [ "$alias" = "exec-bash" ]; then
docker exec -it $2 /bin/bash
elif [ "$alias" = "exec-sh" ]; then
docker exec -it $2 /bin/sh
elif [ "$alias" = "stop-all" ]; then
docker stop `docker ps -qa`
elif [ "$alias" = "rm-uti" ]; then
# Remove all untagged image
docker rmi $(docker images -f "dangling=true" -q)
elif [ "$alias" = "cleanup-all" ]; then
# DANGER!
# This will empty docker! Remove all containers and images.
# Remove all containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
# Remove all images
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -a -q)
else
docker $@
fi
}
## Java
_runPlayFramework() {
port=$1
isDebug=$2
if [ "$port" = "" ]; then
# play run --http.port=8000
activator "~run 8000" # Play 2.x
elif [ "$port" = "-" ] && [ "$isDebug" = "debug" ]; then
activator -jvm-debug 9999 "run 8000"
elif [ "$port" -ne "-" ] && [ "$isDebug" = "debug" ]; then
activator -jvm-debug 9999 "run $port"
else
activator "~run $port"
fi
}
_generateAndroidKeystore() {
keytool -genkey -v -keystore $1.keystore -alias $1 -keyalg RSA -keysize 2048 -validity 10000
}
## SSL
_testSSLCiphers() {
DOMAIN=$1
SERVER=$DOMAIN:443
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
echo Obtaining cipher list from $(openssl version).
for cipher in ${ciphers[@]}
do
echo -n Testing $cipher...
result=$(echo -n | openssl s_client -cipher "$cipher" -connect $SERVER 2>&1)
if [[ "$result" =~ ":error:" ]] ; then
error=$(echo -n $result | cut -d':' -f6)
echo NO \($error\)
else
if [[ "$result" =~ "Cipher is ${cipher}" || "$result" =~ "Cipher :" ]] ; then
echo YES
else
echo UNKNOWN RESPONSE
echo $result
fi
fi
sleep $DELAY
done
}
## IDEA
_idea() {
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
if [ -d "$1" ]; then
wd=`ls -1d "$1" | head -n1`
fi
if [ -f "$1" ]; then
open -a "$IDEA" "$1"
else
pushd $wd > /dev/null
if [ -d ".idea" ]; then
open -a "$IDEA" .
elif [ -f *.ipr ]; then
open -a "$IDEA" `ls -1d *.ipr | head -n1`
elif [ -f pom.xml ]; then
open -a "$IDEA" "pom.xml"
else
open "$IDEA"
fi
popd > /dev/null
fi
}
# credit: http://nparikh.org/notes/zshrc.txt
# Usage: extract <file>
# Description: extracts archived files / mounts disk images
# Note: .dmg/hdiutil is Mac OS X-specific.
_extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar -jxvf $1 ;;
*.tar.gz) tar -zxvf $1 ;;
*.bz2) bunzip2 $1 ;;
*.dmg) hdiutil mount $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar -xvf $1 ;;
*.tbz2) tar -jxvf $1 ;;
*.tgz) tar -zxvf $1 ;;
*.zip) unzip $1 ;;
*.ZIP) unzip $1 ;;
*.pax) cat $1 | pax -r ;;
*.pax.Z) uncompress $1 --stdout | pax -r ;;
*.Z) uncompress $1 ;;
*.rar)
if [ -x "$(command -v unrar)" ]; then
unrar x $1
else
echo "You should install unrar first via 'brew install unrar'."
fi
;;
*) echo "'$1' cannot be extracted/mounted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
## Python Virtualenv
__pyenv_version_ps1 ()
{
# Styles
GREEN="%{$fg[green]%}"
BLUE="%{$fg[blue]%}"
RESET="%{$fg[reset_color]%}"
[[ -n ${VIRTUAL_ENV} ]] || return
echo -n "%{$GREEN%}(${VIRTUAL_ENV:t})%{$RESET%} "
}
PROMPT="\$(__pyenv_version_ps1)${PROMPT}"
## Protect from rm -rf
unsetopt RM_STAR_SILENT
setopt RM_STAR_WAIT