-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_aliases
1191 lines (892 loc) · 23.8 KB
/
.bash_aliases
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Message & notification
show_message() {
local msg=""
local ide=$(echo $TERMINAL_EMULATOR)
local code=""
if [[ ${BASH_VERSION%%[^0-9]*} > 3 ]]; then
code="\e"
else
code="\x1B"
fi
if [ -z $ide ]; then
msg+="$code[0;33m"
else
msg+="$code[37m"
fi
local now=$(date +"%T.%N")
local del_color="$code[0m"
msg+="$now${del_color} "
if [ "$#" == 1 ]; then
msg+="> $1"
else
local text="$2"
local reg='^\w+ing(|\s[^\.]+)$'
if [ -z $ide ]; then
msg+="$code[96m"
else
msg+="$code[34m"
fi
msg+="< $1 >${del_color} ${text}"
if [[ $text =~ $reg ]]; then
msg+="..."
fi
fi
echo -e $msg
}
execute_notification() {
if [ $(uname) == 'Darwin' ]; then
osascript -e "display notification \"$2\" with title \"$1\""
else
notify-send "$1" "$2"
fi
}
# Parse projects info file.
parse_yaml() {
local file_name="$HOME"'/projects.yml'
local prefix='project_'
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $file_name |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
# Get project settings prefix.
get_project() {
eval $(parse_yaml)
local conf=$(( set -o posix ; set ) | cat | grep '^project\_[a-z0-9]*\_local\_directory\='$(pwd)'$')
if [ -z $conf ]; then
echo ''
else
echo 'project_'$(echo $conf | sed 's/^project\_\([^\_]*\).*$/\1/')'_'
fi
}
# Getting variable value.
get() {
eval $(parse_yaml)
echo ${!1}
}
# SSH
execute_remote() {
local project=$(get_project)
if ! [ -z $project ]; then
local environment="$1"
local ssh="${project}${environment}_ssh_"
local host=$(get "${ssh}host")
if ! [ -z $host ]; then
local user=$(get "${ssh}user")
if ! [ -z $user ]; then
local title=$(get "${project}info_title")
show_message "SSH" "Connecting to \"${environment}\" host of \"${title}\" project"
local port=$(get "${ssh}port")
if [ -z $port ]; then
port=22
fi
local directory=$(get "${ssh}directory")
if ! [ -z $directory ]; then
ssh -p ${port} ${user}@${host} -t "cd ${directory} ; bash"
else
ssh -p ${port} ${user}@${host}
fi
else
show_message "SSH" "User not defined!"
fi
else
show_message "SSH" "Host not defined!"
fi
else
show_message "Undefined project!"
fi
}
alias erd="execute_remote dev"
alias erl="execute_remote live"
execute_remote_transfer() {
local project=$(get_project)
if ! [ -z $project ]; then
local environment="$1"
local ssh="${project}${environment}_ssh_"
local host=$(get "${ssh}host")
if ! [ -z $host ]; then
local user=$(get "${ssh}user")
if ! [ -z $user ]; then
local title=$(get "${project}info_title")
show_message "SSH" "Downloading file(s) from \"${environment}\" host of \"${title}\" project"
local port=$(get "${ssh}port")
if [ -z $port ]; then
port=22
fi
scp -P ${port} ${user}@${host}:$2 .
else
show_message "SSH" "User not defined!"
fi
else
show_message "SSH" "Host not defined!"
fi
else
show_message "Undefined project!"
fi
}
alias erdt="execute_remote_transfer dev $1"
alias erlt="execute_remote_transfer live $1"
# Composer
execute_composer_install() {
show_message "Composer" "Installing"
composer install $@
}
alias eci=execute_composer_install
execute_composer_update() {
show_message "Composer" "Updating"
composer update $@
}
alias ecu=execute_composer_update
execute_composer_update_debug() {
show_message "Composer" "Updating in debug mode..."
composer update -vvv $@
}
alias ecud=execute_composer_update_debug
execute_composer_production() {
show_message "Composer" "Updating production"
composer update --no-dev $@
}
alias ecp=execute_composer_production
execute_composer_require() {
show_message "Composer" "Adding package"
composer require $@
}
alias ecr=execute_composer_require
# GIT
alias gs='git status '
alias gb='git branch '
alias gba='git branch -a '
alias gc='git commit -m '
alias gd='git diff '
execute_git_add() {
if [ "$#" == 0 ]; then
show_message "Git" "Adding all changes"
git add .
else
show_message "Git" "Adding some changes"
git add $@
fi
}
alias ega=execute_git_add
execute_git_branch() {
if [ "$#" == 0 ]; then
show_message "Git" "Switching to the previous branch"
git switch -
else
show_message "Git" "Switching to \"$1\" branch"
git switch $1
fi
}
alias egbs=execute_git_branch
execute_git_branch_environment() {
local project=$(get_project)
local branch=''
if ! [ -z $project ]; then
local special_branch=$(get "${project}$1_branch")
if ! [ -z $special_branch ]; then
branch=$special_branch
fi
fi
if [ -z $branch ]; then
for ((i = 2; i <= $#; i++ )); do
local exists=$(git branch --list ${!i})
if ! [ -z "${exists}" ]; then
branch=${!i}
break
fi
done
fi
execute_git_branch $branch
}
alias egbd='execute_git_branch_environment dev dev'
alias egbm='execute_git_branch_environment live master main'
execute_git_changes() {
if [ "$#" == 0 ]; then
show_message "Git" "Canceling all changes"
git checkout .
else
show_message "Git" "Canceling some changes"
git checkout $@
fi
}
alias egch=execute_git_changes
execute_git_delete() {
show_message "Git" "Deleting \"$1\" branch"
git branch -D $1
}
alias egd=execute_git_delete
alias gk='gitk --all&'
alias gx='gitx --all'
alias gf='git fetch '
alias gl='git log '
git_init() {
git init
git config core.fileMode false
}
alias egi=git_init
execute_git_patch() {
show_message "Git" "Applying a patch"
if [ -z $1 ]; then
echo "The command should have at least one parameter!" >> /dev/stderr
else
git apply $@
fi
}
alias egp=execute_git_patch
alias egr='git rm '
alias egrs='git remote -v'
alias egra='git remote add '
alias egrao='git remote add origin '
execute_git_remote_change() {
show_message "Git" "Change origin URL to remote repository"
git remote set-url origin $1
}
alias egrc=execute_git_remote_change
execute_git_revert() {
show_message "Git" "Reverting some existing commit(s)"
git revert $@
}
alias egrv=execute_git_revert
execute_git_clone() {
local remote=""
local directory=""
local branch=""
local user=""
local mail=""
local email=""
local project=false
if [ -d .git ]; then
show_message "Git" "Re-cloning"
remote=$(git remote get-url origin)
directory=${PWD##*/}
branch=$(git rev-parse --abbrev-ref HEAD)
user=$(git config user.name)
mail=$(git config user.mail)
email=$(git config user.email)
if [ -d .idea ]; then
mv .idea ..
project=true
fi
cd ..
sudo rm -rf $directory
else
show_message "Git" "Cloning"
remote=$1
directory=$2
local projects_user=$(get project_git_user)
if ! [ -z "${projects_user}" ]; then
user=$projects_user
fi
local projects_mail=$(get project_git_mail)
if ! [ -z $projects_mail ]; then
mail=$projects_mail
email=$projects_mail
fi
fi
git clone $remote $directory
cd $directory
git config core.fileMode false
if ! [ -z $branch ]; then
execute_git_branch $branch
execute_git_pull $branch
fi
if ! [ -z "${user}" ]; then
git config user.name "${user}"
fi
if ! [ -z $mail ]; then
git config user.mail $mail
fi
if ! [ -z $email ]; then
git config user.email $email
fi
if $project ; then
mv ../.idea .
fi
}
alias egc=execute_git_clone
alias egb='git checkout -b '
alias egcp='git cherry-pick '
alias egcpc='git cherry-pick --continue '
alias egfm='git config core.fileMode '
alias egfmd='git config core.fileMode false '
execute_git_fetch() {
show_message "Git" "Fetching"
git fetch --prune
}
alias egf=execute_git_fetch
alias egm='git merge '
execute_git_push() {
show_message "Git" "Pushing to \"$1\" branch"
git push origin $1
}
alias egh=execute_git_push
execute_git_push_environment() {
local project=$(get_project)
local branch="$1"
if ! [ -z $project ]; then
local special_branch=$(get "${project}$2_branch")
if ! [ -z $special_branch ]; then
branch=$special_branch
fi
fi
execute_git_push $branch
}
alias eghd='execute_git_push_environment develop dev'
alias eghm='execute_git_push_environment master live'
execute_git_pull() {
show_message "Git" "Pulling from \"$1\" branch"
git pull origin $1
}
alias egl=execute_git_pull
execute_git_pull_environment() {
local project=$(get_project)
local branch=''
if ! [ -z $project ]; then
local special_branch=$(get "${project}$1_branch")
if ! [ -z $special_branch ]; then
branch=$special_branch
fi
fi
if [ -z $branch ]; then
for ((i = 2; i <= $#; i++ )); do
local exists=$(git branch --list ${!i})
if ! [ -z "${exists}" ]; then
branch=${!i}
break
fi
done
fi
execute_git_pull $branch
}
alias egld='execute_git_pull_environment dev dev'
alias eglm='execute_git_pull_environment live master main'
git_stash() {
show_message "Git" "Stashing the changes in a dirty working directory away"
git stash $@
}
alias egs=git_stash
git_stash_apply() {
show_message "Git" "Applying a single stashed state on top of the current working tree state"
git stash apply $@
}
alias egsa=git_stash_apply
git_submodule_add_core() {
show_message "Git" "Adding Drupal core as a submodule"
git submodule add --branch 7.x https://git.drupalcode.org/project/drupal.git htdocs
}
alias egsm=git_submodule_add_core
git_submodule_add_module() {
show_message "Git" "Adding a Drupal module as a submodule"
git submodule add --branch 7.x-$2.x https://git.drupalcode.org/project/$1.git sites/all/modules/contrib/$1
}
alias egsma=git_submodule_add_module
git_submodule_update() {
show_message "Git" "Updating submodules"
git submodule update --init $@
}
alias egsmu=git_submodule_update
execute_git_user() {
local name=$(git config user.name)
local email=$(git config user.email)
show_message "Git" "Owner of future commits will be ${name} <${email}>"
}
alias egu=execute_git_user
execute_git_user_fix() {
local user=$(get project_git_user)
if ! [ -z "${user}" ]; then
git config user.name "${user}"
fi
local mail=$(get project_git_mail)
if ! [ -z $mail ]; then
git config user.mail $mail
git config user.email $mail
fi
execute_git_user
}
alias eguf=execute_git_user_fix
# Docker
alias edrs='sudo service docker start '
alias edrp='sudo service docker stop '
docker_clear() {
show_message "Docker" "Stoping containers"
docker stop $(docker ps -q)
show_message "Docker" "Removing containers"
docker rm -f $(docker ps -a -q)
show_message "Docker" "Removing images"
docker rmi -f $(docker images -a -q)
show_message "Docker" "Removing volumes"
docker volume rm $(docker volume ls -q)
show_message "Docker" "Removing networks"
docker network rm $(docker network ls | tail -n+2 | awk '{if($2 !~ /bridge|none|host/){ print $1 }}')
show_message "Docker" "Results"
docker ps -a
docker images -a
docker volume ls
}
alias edrc=docker_clear
execute_docker_list() {
show_message "Docker" "Getting list of running containers"
docker ps --format "table {{.Names}}\t{{.Ports}}\t{{.Image}}\t{{.RunningFor}}\t{{.Status}}"
}
alias edrl=execute_docker_list
execute_docker_execute() {
local arguments=$@
if [ "$#" == 1 ]; then
show_message "Docker" "Connecting to a container"
arguments+=" bash"
elif [[ ${#FUNCNAME[@]} == 1 ]]; then
show_message "Docker" "Executing any command"
fi
docker exec -it ${arguments}
}
alias edre=execute_docker_execute
alias edra='sudo chmod +x $(find . -name "*.sh") '
execute_docker_compose() {
if [ -z $(which docker-compose)]; then
docker compose $@
else
docker-compose $@
fi
}
execute_docker_up() {
show_message "Docker" "Upping"
execute_docker_compose up -d $@
}
alias edru=execute_docker_up
execute_docker_down() {
show_message "Docker" "Downing"
execute_docker_compose down $@
}
alias edrd=execute_docker_down
execute_docker() {
local project=$(get_project)
if ! [ -z $project ]; then
local container=$(get "${project}docker")
if ! [ -z $container ]; then
edre $container $@
return
fi
fi
$@
}
execute_docker_database_container() {
local project=$(get_project)
if ! [ -z $project ]; then
local container=$(get "${project}docker_db")
if ! [ -z $container ]; then
echo $container
return
fi
fi
}
# MySQL
alias ems='sudo service mysql start '
alias emp='sudo service mysql stop '
alias em='mysql -u root -proot '
mysql_import() {
show_message "MySQL" "Importing database"
pv $2 | mysql -u root -proot $1
}
alias emi=mysql_import
mysql_export() {
mysqldump -u root -proot $1 > $2.sql
show_message "MySQL" "Created dump for database called $1 in file $2.sql"
}
alias eme=mysql_export
execute_mysql_create_db() {
show_message "MySQL" "Creating \"$1\" database"
local container=$(execute_docker_database_container)
local database=$1
if [ -z $container ]; then
mysql -u root -proot -e "create database ${database}"
else
docker exec -it $container mysql -u root -proot -e "create database ${database}"
fi
show_message "MySQL" "Created database called \"$1\"."
}
alias emc=execute_mysql_create_db
execute_mysql_drop_db() {
show_message "MySQL" "Deleting \"$1\" database"
local container=$(execute_docker_database_container)
local database=$1
if [ -z $container ]; then
mysql -u root -proot -e "drop database ${database}"
else
docker exec -it $container mysql -u root -proot -e "drop database ${database}"
fi
}
alias emd=execute_mysql_drop_db
execute_mysql_reload() {
local database=$1
local dump="$2"
if [ -z "$dump" ]; then
local project_name=$(get_project)
local project_database=$(get "${project_name}local_database")
if [ -z $database ]; then
database=$project_database
else
if [ -z $project_database ]; then
return
else
dump=$database
database=$project_database
fi
fi
fi
emd $database
emc $database
if [ $# == 0 ]; then
return
fi
local container=$(execute_docker_database_container)
show_message "MySQL" "Loading \"${database}\" database from \"${dump}\" file"
if [ -z $container ]; then
pv $dump | mysql -u root -proot $database
else
if [ -f "$dump" ]; then
docker cp $dump "${container}:/"
fi
docker exec -it $container bash -c "mysql -u root -proot ${database} < ${dump}"
fi
show_message "MySQL" "Recreated \"${database}\" database and load data from \"${dump}\" dump file."
}
alias emr=execute_mysql_reload
mysql_create_user() {
mysql -u root -proot -e "CREATE USER '$1'@'localhost' IDENTIFIED BY '$2'"
mysql -u root -proot -e "GRANT ALL PRIVILEGES ON $1.* TO '$1'@'localhost'"
mysql -u root -proot -e "FLUSH PRIVILEGES"
show_message "MySQL" "Created user \"$1\" for \"$1\" database."
}
alias emu=mysql_create_user
mysql_create_user_special() {
mysql -u root -proot -e "CREATE USER '$2'@'localhost' IDENTIFIED BY '$3'"
mysql -u root -proot -e "GRANT ALL PRIVILEGES ON $1.* TO '$2'@'localhost'"
mysql -u root -proot -e "FLUSH PRIVILEGES"
show_message "MySQL" "Created user \"$2\" for \"$1\" database."
}
alias emus=mysql_create_user_special
# Drush
execute_drush() {
local arguments=$@
local project=$(get_project)
if ! [ -z $project ]; then
local uri=$(get "${project}drush_uri")
if ! [ -z $uri ]; then
arguments+=" --uri=${uri}"
fi
execute_docker drush "${arguments}"
fi
}
execute_drush_execute() {
show_message "Drush" "Executing any command"
execute_drush $@
}
alias eds=execute_drush_execute
execute_drush_clear() {
show_message "Drush" "Clearing all caches"
local project=$(get_project)
local docker=0
if ! [ -z $project ]; then
local container=$(get "${project}docker")
if ! [ -z $container ]; then
execute_drush cr
docker=1
fi
fi
if [ $docker == 0 ]; then
if [ -e index.php ]; then
if [ -e core ]; then
drush cr
else
drush cc all
fi
else
show_message "Site not found!"
fi
fi
}
alias edsc=execute_drush_clear
execute_drush_clear_database() {
show_message "Drush" "Dropping all tables in a given database"
if [ "$#" == 0 ]; then
execute_drush sql-drop --yes
else
execute_drush sql-drop $@
fi
}
alias edscd=execute_drush_clear_database
execute_drush_clear_log() {
show_message "Drush" "Clearing a log"
execute_drush wd-del all -y $@
}
alias edscl=execute_drush_clear_log
execute_drush_cron() {
show_message "Drush" "Running cron"
execute_drush cron
}
alias edsn=execute_drush_cron
execute_drush_clear_root() {
show_message "Drush" "Clearing all caches by root"
execute_docker sudo drush cc all
}
alias edscr=execute_drush_clear_root
execute_drush_dump() {
show_message "Drush" "Creating dump of database"
execute_drush sql-dump --result-file=$1.sql
}
alias edsd=execute_drush_dump
execute_drush_module_install() {
show_message "Drush" "Installing module(s)"
execute_drush -y en $@
}
alias ei=execute_drush_module_install
alias edsmi=execute_drush_module_install
execute_drush_module_uninstall() {
show_message "Drush" "Uninstalling module(s)"
execute_drush -y pmu $@
}
alias edsmu=execute_drush_module_uninstall
execute_drush_config_export() {
show_message "Drush" "Exporting configuration"
execute_drush -y cex
}
alias edsce=execute_drush_config_export
execute_drush_config_import() {
show_message "Drush" "Importing configuration"
execute_drush -y cim
}
alias edsci=execute_drush_config_import
execute_drush_user_login() {
local host='127.0.0.1'
local project=$(get_project)
if ! [ -z $project ]; then
local container=$(get "${project}docker")
if ! [ -z $container ]; then
local ports=$(docker ps --filter name=^/${container}$ --format "{{.Ports}}")
ports="${ports/0.0.0.0:/}"
ports="${ports/->80\/tcp/}"
host+=":${ports}"
fi
fi
local user=$1
if [ -z $user ]; then
user=1
fi
show_message "Drush" "Generating a one time login link for the user account with uid ${user}"
local url=$(execute_drush uli --uid=${user})
echo "${url/default/$host}"
}
alias edsl=execute_drush_user_login
execute_drush_user_login_uid_1_no_browser() {
show_message "Drush" "Display a one time login link for the uid 1 user account without openning browser."
execute_drush uli --uid=$1 --no-browser
}
alias edslfn=execute_drush_uli_uid_no_browser
execute_drush_queue() {
show_message "Drush" "Getting queues"
execute_drush queue-list $@
}
alias edsq=execute_drush_queue
execute_drush_status() {
show_message "Drush" "Getting status"
execute_drush status
}
alias edss=execute_drush_status
execute_drush_status_database() {
show_message "Drush" "Getting database name"
execute_drush status --fields=db-name
}
alias edssd=execute_drush_status_database
execute_drush_update_database() {
show_message "Drush" "Updating database"
execute_drush -y updb
}
alias edsu=execute_drush_update_database
execute_drush_feature() {
show_message "Drush" "Updating feature"
if [ -z $1 ]; then
echo "The command should have one parameter!" >> /dev/stderr
else
execute_drush -y fr $1
fi
}
alias edsf=execute_drush_feature
# Apache
execute_apache() {
show_message "Apache" $1
if [ $(uname) == 'Darwin' ]; then
sudo apachectl $2
else
sudo service apache2 $2
fi
}
alias eas='execute_apache Starting start '
alias ear='execute_apache Restarting restart '
alias eap='execute_apache Stopping stop '
alias eae='sudo a2ensite '
alias ead='sudo a2dissite '
# Tar
execute_tar_extract() {
show_message "Tar" "Extracting"
local file=$1
if [[ $file =~ \.gz$ ]]; then
tar zxfv ${file}
else
tar -xvf ${file}
fi
}
alias ete=execute_tar_extract
# Drupal
execute_drupal_db() {
show_message "Drupal" "Getting database name"
cat sites/default/settings.php | grep "'database'"
}