forked from guarinogabriel/Mac-CLI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac
executable file
·2091 lines (1680 loc) · 85.1 KB
/
mac
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
#!/bin/sh
###########################################################################
# mac CLI (mac command line tools) - OS X command line tools for developers
###########################################################################
# Version: 1.0
# Date: December 8, 2015
# Author: Gabriel Guarino
#
# Notes: Collection of useful functions to automate OS X common
# tasks
#
###########################################################################
#--------------------------------------------------------------------
# Global Variables
#--------------------------------------------------------------------
mysql="/Applications/MAMP/Library/bin/mysql"
mysql_socket="/Applications/MAMP/tmp/mysql/mysql.sock"
mysql_user="root"
mysql_password="root"
mysqldump="/Applications/MAMP/Library/bin/mysqldump"
dropbox_folder="/Volumes/Cloud/Dropbox/"
php="/Applications/MAMP/bin/php/php5.5.26/bin/php"
php_cli="/usr/local/bin/php"
phpmyadmin="http://localhost/phpMyAdmin/"
github_email_account="[email protected]"
github_username="guarinogabriel"
#--------------------------------------------------------------------
# Parameters
#--------------------------------------------------------------------
function=$1
firstParameter=$2
secondParameter=$3
allParameters=${@:2}
#--------------------------------------------------------------------
# Colors
#--------------------------------------------------------------------
GREEN='\033[0;32m'
GRAY='\033[0;37m'
LIGHTBLUE='\033[1;34m'
LIGHTGREEN='\033[1;32m'
WHITEBOLD='\033[1;37m'
RED='\033[1;31m'
NC='\033[0m' # No Color
#--------------------------------------------------------------------
# Utilities
#--------------------------------------------------------------------
# Is the user running commands in sudo?
IS_SUDO=$(id -u)
#--------------------------------------------------------------------
# Functions
#--------------------------------------------------------------------
function spinner()
{
local i sp n
sp='/-\|'
n=${#sp}
printf ' '
while sleep 0.1; do
printf "%s\b" "${sp:i++%n:1}"
done
}
#--------------------------------------------------------------------
# mac script commands list - all commands
#--------------------------------------------------------------------
if [[ "$function" == "list" || "$function" == "help" ]]; then
printf "\n${WHITEBOLD} mac CLI – OS X command line tools for developers\n"
printf "${WHITEBOLD}====================================================\n"
printf "\n${WHITEBOLD}General Utilities: \n"
printf "${LIGHTBLUE}mac install${GRAY}: Install all mac script dependencies to be able to run all commands\n"
printf "${LIGHTBLUE}mac install:all${GRAY}: Install all mac script dependencies and integrated projects\n"
printf "${LIGHTBLUE}mac update${GRAY}: Install OS X software updates, update installed Ruby gems, Homebrew, npm and their installed packages\n"
printf "${LIGHTBLUE}mac lock${GRAY}: Lock\n"
printf "${LIGHTBLUE}mac restart${GRAY}: Restart OS X\n"
printf "${LIGHTBLUE}mac sleep${GRAY}: Sleep mode\n"
printf "${LIGHTBLUE}mac shutdown${GRAY}: Shutdown\n"
printf "${LIGHTBLUE}mac time${GRAY}: Show clock at top right position in Terminal/iTerm\n"
printf "${LIGHTBLUE}mac screensaver${GRAY}: Start screensaver\n"
printf "${LIGHTBLUE}mac folders:list${GRAY}: List folders in current directory with their current size\n"
printf "${LIGHTBLUE}mac folder:size${GRAY}: Calculate current folder size\n"
printf "${LIGHTBLUE}mac folders:remove-empty${GRAY}: Remove empty subdirectories\n"
printf "${LIGHTBLUE}mac apps:close-all${GRAY}: Close all opened apps\n"
printf "${LIGHTBLUE}mac apps:app-store${GRAY}: Get list of installed apps from App Store\n"
printf "${LIGHTBLUE}mac eject-all${GRAY}: Eject all mounted volumes and disks\n"
printf "${LIGHTBLUE}mac battery:status${GRAY}: Get battery information\n"
printf "${LIGHTBLUE}mac info${GRAY}: Get OS X version information\n"
printf "${LIGHTBLUE}mac find:text ${LIGHTGREEN}X${GRAY}: Find exact phrase recursively inside directory - ${LIGHTGREEN}X = Text string\n"
printf "${LIGHTBLUE}mac find:biggest-files ${GRAY}: Find biggest files inside directory\n"
printf "${LIGHTBLUE}mac find:biggest-directories ${GRAY}: Find biggest directories inside directory\n"
printf "${LIGHTBLUE}mac zip:extract ${LIGHTGREEN}X${GRAY}: Extract Zip file to current folder - ${LIGHTGREEN}X = Zip file to extract\n"
printf "${LIGHTBLUE}mac gzip:compress ${LIGHTGREEN}X${GRAY}: Compress current file using Gzip - ${LIGHTGREEN}X = File to compress\n"
printf "${LIGHTBLUE}mac gzip:extract ${LIGHTGREEN}X${GRAY}: Extract Gzip file to current folder - ${LIGHTGREEN}X = Gzip file to extract\n"
printf "${LIGHTBLUE}mac tar:compress ${LIGHTGREEN}X${GRAY}: Compress X file/directory using tar with progress indicator - ${LIGHTGREEN}X = File or directory\n"
printf "${LIGHTBLUE}mac tar:extract ${LIGHTGREEN}X${GRAY}: Extract tar file to current folder - ${LIGHTGREEN}X = Tar file to extract\n"
printf "\n\n${WHITEBOLD}Search Utilities: \n"
printf "${LIGHTBLUE}mac find:recent ${LIGHTGREEN}X${GRAY}: Find files modified in the last N minutes - ${LIGHTGREEN}X = number of minutes \n"
printf "${LIGHTBLUE}mac search:replace ${LIGHTGREEN}X${GRAY}: Search and replace string in file - ${LIGHTGREEN}X = File to perform the search and replace operation\n"
printf "\n\n${WHITEBOLD}Network Utilities: \n"
printf "${LIGHTBLUE}mac speedtest${GRAY}: Internet connection speed test \n"
printf "${LIGHTBLUE}mac speedtest:infinite${GRAY}: Run internet speed test each 5 minutes \n"
printf "${LIGHTBLUE}mac ports${GRAY}: List of used ports \n"
printf "${LIGHTBLUE}mac ip:local${GRAY}: Get local IP address \n"
printf "${LIGHTBLUE}mac ip:public${GRAY}: Get public IP address \n"
printf "\n\n${WHITEBOLD}LAMP Utilities: \n"
printf "${LIGHTBLUE}mac mysql${GRAY}: Open MySQL app \n"
printf "${LIGHTBLUE}mac mysql:cli${GRAY}: Start MySQL CLI with autocompletion and syntax higlighting \n"
printf "${LIGHTBLUE}mac phpmyadmin${GRAY}: Open PHPMyAdmin\n"
printf "${LIGHTBLUE}mac mysql:list${GRAY}: List all MySQL databases\n"
printf "${LIGHTBLUE}mac mysql:export-all${GRAY}: Export all MySQL databases to individual files\n"
printf "${LIGHTBLUE}mac mysql:export ${LIGHTGREEN}X${GRAY}: Export MySQL database to current directory - X = database name \n"
printf "${LIGHTBLUE}mac mysql:import ${LIGHTGREEN}X${GRAY}: Import MySQL database - X = SQL file \n"
printf "${LIGHTBLUE}mac mysql:import-table ${LIGHTGREEN}X${GRAY}: Import single MySQL database table - X = SQL file containing database table \n"
printf "${LIGHTBLUE}mac mysql:create ${LIGHTGREEN}X${GRAY}: Create MySQL database - X = Database name\n"
printf "${LIGHTBLUE}mac mysql:drop ${LIGHTGREEN}X${GRAY}: Remove MySQL database - X = Database name\n"
printf "${LIGHTBLUE}mac mysql:duplicate ${LIGHTGREEN}X${GRAY}: Duplicate MySQL database - X = Database name\n"
printf "${LIGHTBLUE}mac mamp:start${GRAY}: Start MAMP Server (Apache and MySQL)\n"
printf "${LIGHTBLUE}mac mamp:stop${GRAY}: Stop MAMP Server (Apache and MySQL)\n"
printf "${LIGHTBLUE}mac mamp:restart${GRAY}: Restart MAMP Server (Apache and MySQL)\n"
printf "${LIGHTBLUE}mac php:syntax${GRAY}: Check PHP Syntax for all PHP files in current location \n"
printf "${LIGHTBLUE}mac php:info${GRAY}: Get PHP info on command line \n"
printf "${LIGHTBLUE}mac hosts:edit${GRAY}: Edit hosts file \n"
printf "\n\n${WHITEBOLD}SSH Utilities: \n"
printf "${LIGHTBLUE}mac ssh:download-file ${LIGHTGREEN}X${GRAY}: Download file from remote server through SSH - X = Path of the remote file to download \n"
printf "${LIGHTBLUE}mac ssh:download-folder ${LIGHTGREEN}X${GRAY}: Download entire folder from remote server through SSH - X = Path of the remote folder to download \n"
printf "${LIGHTBLUE}mac ssh:download-database ${LIGHTGREEN}X${GRAY}: Download database from remote server through SSH - X = Name of the database to download \n"
printf "${LIGHTBLUE}mac ssh:sync:local ${LIGHTGREEN}X${GRAY}: Sync local folder with remote folder using rsync through SSH (download remote folder to local folder)\n"
printf "${LIGHTBLUE}mac ssh:sync:remote ${LIGHTGREEN}X${GRAY}: Path of the remote folder to sync from local folder (upload local folder to remote folder) \n"
printf "${LIGHTBLUE}mac ssh:upload ${LIGHTGREEN}X${GRAY}: Upload file to remote server through SSH - X = Path of the file to upload to the remote server \n"
printf "${LIGHTBLUE}mac ssh:public-key ${LIGHTGREEN}X${GRAY}: Get public SSH key for local machine \n"
printf "${LIGHTBLUE}mac ssh:list ${LIGHTGREEN}X${GRAY}: List all the saved SSH credentials \n"
printf "\n\n${WHITEBOLD}Web Development Utilities: \n"
printf "${LIGHTBLUE}mac dev:monitor ${LIGHTGREEN}X${GRAY}: Monitor file changes (for example: log file) - X = File to monitor \n"
printf "${LIGHTBLUE}mac dev:compass:compile ${LIGHTGREEN}X${GRAY}: Compile current folder using compass \n"
printf "${LIGHTBLUE}mac dev:optimize-images${GRAY}: Optimize all images in current directory and subdirectories \n"
printf "${LIGHTBLUE}mac dev:css:convert-to-scss${GRAY}: Convert CSS file to SCSS \n"
printf "\n\n${WHITEBOLD}Performance and maintenance Utilities: \n"
printf "${LIGHTBLUE}mac system${GRAY}: Show system information to review mac performance \n"
printf "${LIGHTBLUE}mac temp${GRAY}: Show temperature, fan and battery statistics \n"
printf "${LIGHTBLUE}mac memory${GRAY}: See memory usage sorted by memory consumption \n"
printf "${LIGHTBLUE}mac trash:empty${GRAY}: Empty trash\n"
printf "${LIGHTBLUE}mac trash:size${GRAY}: Calculate trash size\n"
printf "${LIGHTBLUE}mac desktop:cleanup${GRAY}: Remove all files and directories from the Desktop directory\n"
printf "${LIGHTBLUE}mac downloads:cleanup${GRAY}: Remove all files and directories from the Downloads directory\n"
printf "\n\n${WHITEBOLD}iTerm / Terminal Utilities: \n"
printf "${LIGHTBLUE}mac iterm:tab-title${GRAY}: Set title to current iTerm tab \n"
printf "\n\n${WHITEBOLD}Git Utilities: \n"
printf "${LIGHTBLUE}mac git:config${GRAY}: Display local Git configuration \n"
printf "${LIGHTBLUE}mac git:open${GRAY}: Open current repository on Github \n"
printf "${LIGHTBLUE}mac git:create:branch${GRAY}: Create branch based on current branch \n"
printf "${LIGHTBLUE}mac git:branches:date${GRAY}: Get last update date for all branches in current project \n"
printf "${LIGHTBLUE}mac git:undo-commit${GRAY}: Undo latest commit \n"
printf "${LIGHTBLUE}mac git:log${GRAY}: See latest commits IDs and titles for current branch \n"
printf "${LIGHTBLUE}mac git:branch${GRAY}: See all branches \n"
printf "${LIGHTBLUE}mac git:branch:rename${GRAY}: Rename Git branch \n"
printf "${LIGHTBLUE}mac git:branch:remove-local${GRAY}: Remove local Git branch \n"
printf "${LIGHTBLUE}mac git:branch:remove-remote${GRAY}: Remove local and remote Git branch \n"
printf "${LIGHTBLUE}mac git:removeprintf "${LIGHTBLUE}mac git:branch${GRAY}: See all branches \n"${GRAY}: Remove Git from current project \n"
printf "${LIGHTBLUE}mac git:settings${GRAY}: Check Git settings \n"
printf "${LIGHTBLUE}mac git:add-removed${GRAY}: Add removed files to staged files \n"
printf "${LIGHTBLUE}mac git:size${GRAY}: Get size for current Git repository \n"
printf "${LIGHTBLUE}mac github:streak${GRAY}: See current Git contribution streak \n"
printf "\n\n${WHITEBOLD}Web Utilities: \n"
printf "${LIGHTBLUE}mac web:download-images${GRAY}: Download all images from website to current directory \n"
printf "\n\n${WHITEBOLD}Homebrew Utilities: \n"
printf "${LIGHTBLUE}mac brew:list${GRAY}: Get list of installed Homebrew packages \n"
printf "\n\n${WHITEBOLD}Xcode Utilities: \n"
printf "${LIGHTBLUE}mac xcode:cleanup${GRAY}: Cleanup XCode files to free up hard disk space \n"
printf "\n\n${WHITEBOLD}Image Utilities: \n"
printf "${LIGHTBLUE}mac image:generate:mobile-app-icons ${LIGHTGREEN}X Y${GRAY}: Generate mobile app icons - X = Path of the original image file, Y= Path of the output file path \n"
printf "\n\n${WHITEBOLD}Magento Utilities: \n"
printf "${LIGHTBLUE}mac magento:version${GRAY}: Get Magento version from current project on command line \n"
printf "${LIGHTBLUE}mac magento:customer:create${GRAY}: Create Magento customer with sample address and sample credit card information \n"
printf "${LIGHTBLUE}mac magento:fix-permissions${GRAY}: Fix Magento permissions for files and directories \n"
printf "${LIGHTBLUE}mac magento:order:create${GRAY}: Create sample order in Magento \n"
printf "${LIGHTBLUE}mac magento:shell-script:create${GRAY}: Create script in Magento shell folder to be run from command line \n"
printf "${LIGHTBLUE}mac magento:gitignore:create${GRAY}: Create gitignore file for Magento project \n"
printf "${LIGHTBLUE}mac magento:url-rewrite:enables${GRAY}: Enable Magento URL rewrites \n"
printf "${LIGHTBLUE}mac magento:url-rewrites:disable${GRAY}: Disable Magento URL rewrites \n"
printf "${LIGHTBLUE}mac magento2:install${GRAY}: Install Magento 2 in current directory \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - general commands
#--------------------------------------------------------------------
elif [ "$function" == "list:general" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n${WHITEBOLD}General Utilities: \n"
printf "${LIGHTBLUE}mac install${GRAY}: Install all mac script dependencies to be able to run all commands\n"
printf "${LIGHTBLUE}mac install:all${GRAY}: Install all mac script dependencies and integrated projects\n"
printf "${LIGHTBLUE}mac update${GRAY}: Install OS X software updates, update installed Ruby gems, Homebrew, npm and their installed packages\n"
printf "${LIGHTBLUE}mac lock${GRAY}: Lock\n"
printf "${LIGHTBLUE}mac restart${GRAY}: Restart OS X\n"
printf "${LIGHTBLUE}mac sleep${GRAY}: Sleep mode\n"
printf "${LIGHTBLUE}mac shutdown${GRAY}: Shutdown\n"
printf "${LIGHTBLUE}mac time${GRAY}: Show clock at top right position in Terminal/iTerm\n"
printf "${LIGHTBLUE}mac screensaver${GRAY}: Start screensaver\n"
printf "${LIGHTBLUE}mac folders:list${GRAY}: List folders in current directory with their current size\n"
printf "${LIGHTBLUE}mac folder:size${GRAY}: Calculate current folder size\n"
printf "${LIGHTBLUE}mac folders:remove-empty${GRAY}: Remove empty subdirectories\n"
printf "${LIGHTBLUE}mac apps:close-all${GRAY}: Close all opened apps\n"
printf "${LIGHTBLUE}mac apps:app-store${GRAY}: Get list of installed apps from App Store\n"
printf "${LIGHTBLUE}mac eject-all${GRAY}: Eject all mounted volumes and disks\n"
printf "${LIGHTBLUE}mac battery:status${GRAY}: Get battery information\n"
printf "${LIGHTBLUE}mac info${GRAY}: Get OS X version information\n"
printf "${LIGHTBLUE}mac find:text ${LIGHTGREEN}X${GRAY}: Find exact phrase recursively inside directory - ${LIGHTGREEN}X = Text string\n"
printf "${LIGHTBLUE}mac find:biggest-files ${LIGHTGREEN}X${GRAY}: Find biggest files inside directory\n"
printf "${LIGHTBLUE}mac find:duplicated ${GRAY}: Find duplicated files in current directory and subcategories\n"
printf "${LIGHTBLUE}mac find:biggest-directories ${LIGHTGREEN}X${GRAY}: Find biggest directories inside directory\n"
printf "${LIGHTBLUE}mac zip:extract ${LIGHTGREEN}X${GRAY}: Extract Zip file to current folder - ${LIGHTGREEN}X = Zip file to extract\n"
printf "${LIGHTBLUE}mac gzip:compress ${LIGHTGREEN}X${GRAY}: Compress current file using Gzip - ${LIGHTGREEN}X = File to compress\n"
printf "${LIGHTBLUE}mac gzip:extract ${LIGHTGREEN}X${GRAY}: Extract Gzip file to current folder - ${LIGHTGREEN}X = Gzip file to extract\n"
printf "${LIGHTBLUE}mac tar:compress ${LIGHTGREEN}X${GRAY}: Compress X file/directory using tar with progress indicator - ${LIGHTGREEN}X = File or directory\n"
printf "${LIGHTBLUE}mac tar:extract ${LIGHTGREEN}X${GRAY}: Extract tar file to current folder - ${LIGHTGREEN}X = Tar file to extract\n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - search commands
#--------------------------------------------------------------------
elif [ "$function" == "list:search" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Search Utilities: \n"
printf "${LIGHTBLUE}mac find:recent ${LIGHTGREEN}X${GRAY}: Find files modified in the last N minutes - ${LIGHTGREEN}X = number of minutes \n"
printf "${LIGHTBLUE}mac find:duplicated ${GRAY}: Find duplicated files in current directory and subcategories\n"
printf "${LIGHTBLUE}mac search:replace ${LIGHTGREEN}X${GRAY}: Search and replace string in file - ${LIGHTGREEN}X = File to perform the search and replace operation\n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - network commands
#--------------------------------------------------------------------
elif [ "$function" == "list:network" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Network Utilities: \n"
printf "${LIGHTBLUE}mac speedtest${GRAY}: Internet connection speed test \n"
printf "${LIGHTBLUE}mac speedtest:infinite${GRAY}: Run internet speed test each 5 minutes \n"
printf "${LIGHTBLUE}mac ports${GRAY}: List of used ports \n"
printf "${LIGHTBLUE}mac ip:local${GRAY}: Get local IP address \n"
printf "${LIGHTBLUE}mac ip:public${GRAY}: Get public IP address \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - LAMP commands
#--------------------------------------------------------------------
elif [ "$function" == "list:lamp" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}LAMP Utilities: \n"
printf "${LIGHTBLUE}mac mysql${GRAY}: Open MySQL app \n"
printf "${LIGHTBLUE}mac mysql-cli${GRAY}: Start MySQL CLI with autocompletion and syntax higlighting \n"
printf "${LIGHTBLUE}mac phpmyadmin${GRAY}: Open PHPMyAdmin\n"
printf "${LIGHTBLUE}mac mysql:list${GRAY}: List all MySQL databases\n"
printf "${LIGHTBLUE}mac mysql:export-all${GRAY}: Export all MySQL databases to individual files\n"
printf "${LIGHTBLUE}mac mysql:export ${LIGHTGREEN}X${GRAY}: Export MySQL database to current directory - X = database name \n"
printf "${LIGHTBLUE}mac mysql:import ${LIGHTGREEN}X${GRAY}: Import MySQL database - X = SQL file \n"
printf "${LIGHTBLUE}mac mysql:import-table ${LIGHTGREEN}X${GRAY}: Import single MySQL database table - X = SQL file containing database table \n"
printf "${LIGHTBLUE}mac mysql:create ${LIGHTGREEN}X${GRAY}: Create MySQL database - X = Database name\n"
printf "${LIGHTBLUE}mac mysql:drop ${LIGHTGREEN}X${GRAY}: Remove MySQL database - X = Database name\n"
printf "${LIGHTBLUE}mac mysql:duplicate ${LIGHTGREEN}X${GRAY}: Duplicate MySQL database - X = Database name\n"
printf "${LIGHTBLUE}mac mamp:start${GRAY}: Start MAMP Server (Apache and MySQL)\n"
printf "${LIGHTBLUE}mac mamp:stop${GRAY}: Stop MAMP Server (Apache and MySQL)\n"
printf "${LIGHTBLUE}mac mamp:restart${GRAY}: Restart MAMP Server (Apache and MySQL)\n"
printf "${LIGHTBLUE}mac php:syntax${GRAY}: Check PHP Syntax for all PHP files in current location \n"
printf "${LIGHTBLUE}mac php:info${GRAY}: Get PHP info on command line \n"
printf "${LIGHTBLUE}mac hosts:edit${GRAY}: Edit hosts file \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - SSH commands
#--------------------------------------------------------------------
elif [ "$function" == "list:ssh" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}SSH Utilities: \n"
printf "${LIGHTBLUE}mac ssh:download-file ${LIGHTGREEN}X${GRAY}: Download file from remote server through SSH - X = Path of the remote file to download \n"
printf "${LIGHTBLUE}mac ssh:download-folder ${LIGHTGREEN}X${GRAY}: Download entire folder from remote server through SSH - X = Path of the remote folder to download \n"
printf "${LIGHTBLUE}mac ssh:download-database ${LIGHTGREEN}X${GRAY}: Download database from remote server through SSH - X = Name of the database to download \n"
printf "${LIGHTBLUE}mac ssh:sync:local ${LIGHTGREEN}X${GRAY}: Sync local folder with remote folder using rsync through SSH (download remote folder to local folder)\n"
printf "${LIGHTBLUE}mac ssh:sync:remote ${LIGHTGREEN}X${GRAY}: Path of the remote folder to sync from local folder (upload local folder to remote folder) \n"
printf "${LIGHTBLUE}mac ssh:upload ${LIGHTGREEN}X${GRAY}: Upload file to remote server through SSH - X = Path of the file to upload to the remote server \n"
printf "${LIGHTBLUE}mac ssh:public-key${GRAY}: Copy SSH Public Key \n"
printf "${LIGHTBLUE}mac ssh:list ${LIGHTGREEN}X${GRAY}: List all the saved SSH credentials \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - web development commands
#--------------------------------------------------------------------
elif [ "$function" == "list:dev" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Web Development Utilities: \n"
printf "${LIGHTBLUE}mac monitor ${LIGHTGREEN}X${GRAY}: Monitor file changes (for example: log file) - X = File to monitor \n"
printf "${LIGHTBLUE}mac compass:compile ${LIGHTGREEN}X${GRAY}: Compile current folder using compass"
printf "${LIGHTBLUE}mac dev:optimize-images${GRAY}: Optimize all images in current directory and subdirectories \n"
printf "${LIGHTBLUE}mac dev:css:convert-to-scss${GRAY}: Convert CSS file to SCSS \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - performance commands
#--------------------------------------------------------------------
elif [ "$function" == "list:performance" ]; then
printf "\n${WHITEBOLD} mac – OS X command line tools for developers\n"
printf "${WHITEBOLD}================================================"
printf "\n\n${WHITEBOLD}Performance and maintenance Utilities: \n"
printf "${LIGHTBLUE}mac system${GRAY}: Show system information to review mac performance \n"
printf "${LIGHTBLUE}mac temp${GRAY}: Show temperature, fan and battery statistics \n"
printf "${LIGHTBLUE}mac memory${GRAY}: See memory usage sorted by memory consumption \n"
printf "${LIGHTBLUE}mac trash:empty${GRAY}: Empty trash\n"
printf "${LIGHTBLUE}mac trash:size${GRAY}: Calculate trash size\n"
printf "${LIGHTBLUE}mac desktop:cleanup${GRAY}: Remove all files and directories from the Desktop directory\n"
printf "${LIGHTBLUE}mac downloads:cleanup${GRAY}: Remove all files and directories from the Downloads directory\n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - terminal commands
#--------------------------------------------------------------------
elif [ "$function" == "list:terminal" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}iTerm / Terminal Utilities: \n"
printf "${LIGHTBLUE}mac iterm:tab-title${GRAY}: Set title to current iTerm tab \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - Git commands
#--------------------------------------------------------------------
elif [ "$function" == "list:git" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Git Utilities: \n"
printf "${LIGHTBLUE}mac git:config${GRAY}: Display local Git configuration \n"
printf "${LIGHTBLUE}mac git:open${GRAY}: Open current repository on Github \n"
printf "${LIGHTBLUE}mac git:create:branch${GRAY}: Create branch based on current branch \n"
printf "${LIGHTBLUE}mac git:branches${GtRAY}: Get last update date for all branches in current project \n"
printf "${LIGHTBLUE}mac git:undo-commit${GRAY}: Undo latest commit \n"
printf "${LIGHTBLUE}mac git:log${GRAY}: See latest commits IDs and titles for current branch \n"
printf "${LIGHTBLUE}mac git:branch${GRAY}: See all branches \n"
printf "${LIGHTBLUE}mac git:branch:rename${GRAY}: Rename Git branch \n"
printf "${LIGHTBLUE}mac git:branch:remove-local${GRAY}: Remove local Git branch \n"
printf "${LIGHTBLUE}mac git:branch:remove-remote${GRAY}: Remove local and remote Git branch \n"
printf "${LIGHTBLUE}mac git:remove${GRAY}: Remove Git from current project \n"
printf "${LIGHTBLUE}mac git:settings${GRAY}: Check Git settings \n"
printf "${LIGHTBLUE}mac git:add-removed${GRAY}: Add removed files to staged files \n"
printf "${LIGHTBLUE}mac git:size${GRAY}: Get size for current Git repository \n"
printf "${LIGHTBLUE}mac github:streak${GRAY}: See current Git contribution streak \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - web commands
#--------------------------------------------------------------------
elif [ "$function" == "list:web" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Web Utilities: \n"
printf "${LIGHTBLUE}mac web:download-images${GRAY}: Download all images from website to current directory \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - homebrew commands
#--------------------------------------------------------------------
elif [ "$function" == "list:brew" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Homebrew Utilities: \n"
printf "${LIGHTBLUE}mac brew:list${GRAY}: Get list of installed Homebrew packages \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - xCode commands
#--------------------------------------------------------------------
elif [ "$function" == "list:xcode" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Xcode Utilities: \n"
printf "${LIGHTBLUE}mac xcode:cleanup${GRAY}: Cleanup XCode files to free up hard disk space \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - Image commands
#--------------------------------------------------------------------
elif [ "$function" == "list:image" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Image Utilities: \n"
printf "${LIGHTBLUE}mac image:generate:mobile-app-icons ${LIGHTGREEN}X Y${GRAY}: Generate mobile app icons - X = Path of the original image file, Y= Path of the output file path \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# mac script commands list - Magento commands
#--------------------------------------------------------------------
elif [ "$function" == "list:magento" ]; then
printf "\n${WHITEBOLD} mac – automation tools for OS X\n"
printf "${WHITEBOLD}==================================="
printf "\n\n${WHITEBOLD}Magento Utilities: \n"
printf "${LIGHTBLUE}mac magento:version${GRAY}: Get Magento version from current project on command line \n"
printf "${LIGHTBLUE}mac magento:customer:create${GRAY}: Create Magento customer with sample address and sample credit card information \n"
printf "${LIGHTBLUE}mac magento:fix-permissions${GRAY}: Fix Magento permissions for files and directories \n"
printf "${LIGHTBLUE}mac magento:order:create${GRAY}: Create sample order in Magento \n"
printf "${LIGHTBLUE}mac magento:shell-script:create${GRAY}: Create script in Magento shell folder to be run from command line \n"
printf "${LIGHTBLUE}mac magento:gitignore:create${GRAY}: Create gitignore file for Magento project \n"
printf "${LIGHTBLUE}mac magento:url-rewrites:enable${GRAY}: Enable Magento URL rewrites \n"
printf "${LIGHTBLUE}mac magento:url-rewrites:disable${GRAY}: Disable Magento URL rewrites \n"
printf "${LIGHTBLUE}mac magento2:install${GRAY}: Install Magento 2 in current directory \n"
printf "${NC}\n"
#--------------------------------------------------------------------
# General Utilities
#--------------------------------------------------------------------
elif [ "$function" == "lock" ]; then
printf "${GREEN}/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend\n\n${NC}"
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
elif [ "$function" == "restart" ]; then
printf "${GREEN}osascript -e 'tell app 'loginwindow' to «event aevtrrst»''\n\n${NC}"
osascript -e 'tell app "loginwindow" to «event aevtrrst»'
elif [ "$function" == "sleep" ]; then
printf "${GREEN}pmset sleepnow\n\n${NC}"
pmset sleepnow
elif [ "$function" == "shutdown" ]; then
printf "${GREEN}osascript -e 'tell app 'loginwindow' to «event aevtrsdn»'\n\n${NC}"
osascript -e 'tell app "loginwindow" to «event aevtrsdn»'
elif [ "$function" == "time" ]; then
printf "${GREEN}while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &'\n\n${NC}"
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &
# Remove files older than X days in current folder
elif [ "$function" == "files:remove-older" ]; then
printf "${GREEN}find . -ctime +${GRAY}${firstParameter}${GREEN} -print0 | xargs -0 -n1\n\n${NC}"
echo "Removing files older than "$firstParameter" days..."
find . -ctime +$firstParameter -print0 | xargs -0 -n1
# Calculate folder size
elif [ "$function" == "folder:size" ]; then
printf "${GREEN}du -sh .\n\n${NC}"
echo "Calculating folder size...\n"
echo "Folder size:"
du -sh .
# List folders in current directory
elif [ "$function" == "folders:list" ]; then
du -sk * | sort -g | awk '{ numBytes = $1 * 1024; numUnits = split("B K M G T P", unit); num = numBytes; iUnit = 0; while(num >= 1024 && iUnit + 1 < numUnits) { num = num / 1024; iUnit++; } $1 = sprintf( ((num == 0) ? "%6d%s " : "%6.1f%s "), num, unit[iUnit + 1]); print $0; }'
# Remove empty subdirectories
elif [ "$function" == "folders:remove-empty" ]; then
printf "${GREEN}find . -type d -empty -delete\n\n${NC}"
find . -type d -empty -delete
# Close all opened apps
elif [ "$function" = "apps:close-all" ]; then
printf "${GREEN}ignore='grep\|iTerm\|Finder\|Dropbox\|Bartender'\n${NC}"
printf "${GREEN}ps aux | grep /Applications | grep -v $ignore | sed "s/\ *\ /\ /g" | cut -d ' ' -f 2 | xargs -I X kill -9 X\n\n${NC}"
# To customize ignored apps, just put the keywords in $ignore
# To test which apps you are going to kill, run:
# ps aux | grep /Applications | grep -v $ignore | sed "s/\ *\ /\ /g" | cut -d ' ' -f 11 | xargs -I X echo X
ignore="grep\|iTerm\|Finder\|Dropbox\|Bartender"
ps aux | grep /Applications | grep -v $ignore | sed "s/\ *\ /\ /g" | cut -d ' ' -f 2 | xargs -I X kill -9 X
# Get list of installed apps from the App Store
elif [ "$function" == "apps:app-store" ]; then
printf "${GREEN}find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |\sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'\n\n${NC}"
echo "Getting list of installed apps from the App Store...\n"
find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |\sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'
# Start screensaver
elif [ "$function" == "screensaver" ]; then
printf "${GREEN}open -a /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app\n\n${NC}"
open -a /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app
# Eject all mounted volumes and disk
elif [ "$function" == "eject-all" ]; then
printf "${GREEN}osascript -e 'tell application 'Finder' to eject (every disk whose executable is true)'\n\n${NC}"
osascript -e 'tell application "Finder" to eject (every disk whose executable is true)'
# Get battery information
elif [ "$function" == "battery:status" ]; then
printf "${GREEN}system_profiler SPPowerDataType | awk '/Full/ || /Remaining/ || /Cycle/ { printf }' | sed -e 's/[^:]*/Battery/' -e 's/ *R.*):./\//' -e 's/ *Cycle/ (mAh) Cycle/'\n\n${NC}"
system_profiler SPPowerDataType | awk '/Full/ || /Remaining/ || /Cycle/ { printf }' | sed -e 's/[^:]*/Battery/' -e 's/ *R.*):./\//' -e 's/ *Cycle/ (mAh) Cycle/'
# Install all mac script dependencies
elif [ "$function" == "install" ]; then
echo "Copying script to local folder..."
cp mac /usr/local/bin/mac
echo "Installing homebrew..."
printf "${GREEN}/usr/bin/ruby -e '\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'\n${NC}"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Installing Git..."
printf "${GREEN}brew install git\n${NC}"
brew install git
echo "Installing pv (Pipe Viewer)..."
printf "${GREEN}brew install pv\n${NC}"
brew install pv
echo "Installing Python..."
printf "${GREEN}brew install python\n${NC}"
brew install python
echo "Installing fdupes..."
printf "${GREEN}brew install fdupes\n\n${NC}"
brew install fdupes
# Install all mac script dependencies and integrated projects
elif [ "$function" == "install:all" ]; then
echo "Copying script to local folder..."
cp mac /usr/local/bin/mac
echo "Installing homebrew..."
printf "${GREEN}/usr/bin/ruby -e '\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'\n${NC}"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Installing Git..."
printf "${GREEN}brew install git\n${NC}"
brew install git
echo "Installing pv (Pipe Viewer)..."
printf "${GREEN}brew install pv\n${NC}"
brew install pv
echo "Installing Python..."
printf "${GREEN}brew install python\n${NC}"
brew install python
mac install
echo "Installing mycli (MySQL CLI - https://github.com/dbcli/mycli)..."
printf "${GREEN}brew install mycli\n${NC}"
brew install mycli
echo "Installing Compass..."
printf "${GREEN}gem install compass\n${NC}"
gem install compass
echo "Installing Glances (https://github.com/nicolargo/glances)..."
printf "${GREEN}pip install glances\n${NC}"
pip install glances
echo "Installing SpeedTest CLI (https://github.com/sivel/speedtest-cli)..."
printf "${GREEN}pip install speedtest-cli\n${NC}"
pip install speedtest-cli
echo "Installing N98 Magerun (https://github.com/netz98/n98-magerun)..."
printf "${GREEN}wget https://files.magerun.net/n98-magerun.phar\n${NC}"
wget https://files.magerun.net/n98-magerun.phar
printf "${GREEN}chmod +x ./n98-magerun.phar\n${NC}"
chmod +x ./n98-magerun.phar
printf "${GREEN}sudo mv ./n98-magerun.phar /usr/local/bin/\n${NC}"
sudo mv ./n98-magerun.phar /usr/local/bin/
echo "Installing N98 Magerun 2 (https://github.com/netz98/n98-magerun2)..."
printf "${GREEN}wget https://files.magerun.net/n98-magerun2.phar\n${NC}"
wget https://files.magerun.net/n98-magerun2.phar
printf "${GREEN}chmod +x ./n98-magerun2.phar\n${NC}"
chmod +x ./n98-magerun2.phar
printf "${GREEN}sudo mv ./n98-magerun2.phar /usr/local/bin/\n${NC}"
sudo mv ./n98-magerun2.phar /usr/local/bin/
echo "Installing composer..."
printf "${GREEN}curl -sS https://getcomposer.org/installer | php\n${NC}"
curl -sS https://getcomposer.org/installer | php
printf "${GREEN}sudo mv composer.phar /usr/local/bin/\n${NC}"
sudo mv composer.phar /usr/local/bin/
echo "Installing Git cal (https://github.com/k4rthik/git-cal)..."
printf "${GREEN}brew install git-cal\n${NC}"
brew install git-cal
echo "Installing ImageOptim..."
printf "${GREEN}brew cask install --appdir="~/Applications" imageoptim --force\n${NC}"
brew cask install --appdir="~/Applications" imageoptim --force
echo "Installing ImageOptim-CLI (https://github.com/JamieMason/ImageOptim-CLI)..."
printf "${GREEN}npm install -g imageoptim-cli\n${NC}"
npm install -g imageoptim-cli
echo "Installing sass..."
printf "${GREEN}sudo gem install sass\n${NC}"
sudo gem install sass
echo "Installing storm (https://github.com/emre/storm)..."
printf "${GREEN}brew install stormssh\n${NC}"
brew install stormssh
echo "Installing fdupes..."
printf "${GREEN}brew install fdupes\n\n${NC}"
brew install fdupes
echo "Installing iStats..."
printf "${GREEN}sudo gem install iStats -n/usr/local/bin\n\n${NC}"
sudo gem install iStats -n/usr/local/bin
# Install OS X software updates, update installed Ruby gems, Homebrew, npm, pip and their installed packages
elif [ "$function" == "update" ]; then
echo "Updating OS X..."
printf "${GREEN}sudo softwareupdate -i -a;\n${NC}"
sudo softwareupdate -i -a;
echo "Updating Homebrew and its installed packages..."
printf "${GREEN}brew update; brew upgrade --all; brew cleanup;\n${NC}"
brew update; brew upgrade --all; brew cleanup;
echo "Updating npm and its installed packages..."
printf "${GREEN}npm install npm -g; npm update -g;\n${NC}"
npm install npm -g; npm update -g;
echo "Updating installed Ruby gems..."
printf "${GREEN}sudo gem update --system; sudo gem update\n${NC}"
sudo gem update --system; sudo gem update
echo "Updating installed pip packages..."
printf "${GREEN}pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U\n${NC}"
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
echo "Updating N98-Magerun..."
printf "${GREEN}n98-magerun.phar self-update\n${NC}"
n98-magerun.phar self-update
echo "Updating N98-Magerun 2..."
printf "${GREEN}n98-magerun2.phar self-update\n${NC}"
n98-magerun2.phar self-update
echo "Your system has been successfully updated"
# Find text in current directory
elif [ "$function" == "find:text" ]; then
if [ ! -z "$allParameters" -a "$allParameters" != " " ]; then
echo "Please enter the extension to search (i.e.: csv): "
read extension
if [ ! -z "$extension" -a "$extension" != " " ]; then
printf "${GREEN}find . -iname '*.${GRAY}${extension}${GREEN}' | xargs grep -in --color '${GRAY}${allParameters}${GREEN}'${NC}"
echo "\nRecursively find '"$allParameters"' inside directory...\n"
find . -iname "*.$extension" | xargs grep -in --color "$allParameters"
else
echo "Please introduce the extension of the files to search. E.g: csv\n"
fi
else
echo "Please introduce text to search. E.g:\n"
echo "mac find:text Sample Search Text"
fi
# Find biggest files in current directory
elif [ "$function" == "find:biggest-files" ]; then
printf "${GREEN}find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}${NC}"
find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
# Find biggest directories in current directory
elif [ "$function" == "find:biggest-directories" ]; then
printf "${GREEN}find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}${NC}"
find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
# Extract Zip file
elif [ "$function" == "zip:extract" ]; then
if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
printf "${GREEN}unzip ${GRAY}${firstParameter}\n\n${NC}"
unzip $firstParameter
else
echo "Please specify the Zip file to extract.\n"
echo "E.g.: zip:extract sample_file.zip"
fi
# Compress Gzip file
elif [ "$function" == "gzip:compress" ]; then
if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
printf "${GREEN}gzip ${GRAY}${firstParameter}\n\n${NC}"
gzip $firstParameter
else
echo "Please specify the file to compress.\n"
echo "E.g.: gzip:compress sample_file"
fi
# Extract Gzip file
elif [ "$function" == "gzip:extract" ]; then
if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
printf "${GREEN}gzip -d ${GRAY}${firstParameter}\n\n${NC}"
gzip -d $firstParameter
else
echo "Please specify the Gzip file to extract.\n"
echo "E.g.: gzip:extract sample_file.gz"
fi
# Extract tar file
elif [ "$function" == "tar:extract" ]; then
if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
printf "${GREEN}tar -xvzf ${GRAY}${firstParameter}\n\n${NC}"
tar -xvzf $firstParameter
else
echo "Please specify the tar file to extract.\n"
echo "E.g.: tar:extract sample_file.tgz"
fi
# Compress file/folder using TAR with progress indicator
elif [ "$function" == "tar:compress" ]; then
echo "Please enter the filename to save the .tgz file: "
if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
read filename
if [ ! -z "$filename" -a "$filename" != " " ]; then
printf "${GREEN}tar -czf${GRAY}: ${firstParameter}${GREEN} | (pv -p --timer --rate --bytes > '${GRAY}${filename}${GREEN}'.tgz)\n\n${NC}"
tar -czf - $firstParameter | (pv -p --timer --rate --bytes > "$filename".tgz)
else
"Please specify the file name"
fi
else
echo "Please specify the folder or directory to compress."
echo "E.g.: tar:compress foldername"
fi
# Search and replace string on file
elif [ "$function" == "search:replace" ]; then
echo "Please enter the string to search on the file:"
if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
read searchString
if [ ! -z "$searchString" -a "$searchString" != " " ]; then
echo "Please enter the string that will replace the search string:"
read replaceString
if [ ! -z "$replaceString" -a "$replaceString" != " " ]; then
printf "${GREEN}LC_CTYPE=C sed -i 's#${GRAY}${searchString}${GREEN}#${GRAY}${replaceString}${GREEN}#g' ${GRAY}${firstParameter}\n\n${NC}"
LC_CTYPE=C sed -i 's#'"${searchString}"'#'"${replaceString}"'#g' $firstParameter
else
"Please specify the string to replace"
fi
else
"Please specify the string to search"
fi
else
echo "Please specify the file to perform the search and replace operation"
echo "E.g.: search:replace /path/to/file.csv"
fi
# TODO: Working on airplane mode (disable wi-fi and bluetooth)
elif [ "$function" == "airplane-mode:on" ]; then
echo "Enabling airplane mode...\n"
# networksetup -setairportpower airport off
# networksetup -setairportpower en0 off
# networksetup -setairportpower en1 off
# launchctl unload -w /System/Library/LaunchDaemons/com.apple.blued.plist # Switch bluetooth off
elif [ "$function" == "airplane-mode:off" ]; then
echo "Disabling airplane mode...\n"
# networksetup -setairportpower airport on
# networksetup -setairportpower en0 on
# networksetup -setairportpower en1 on
# launchctl load -wF /System/Library/LaunchDaemons/com.apple.blued.plist # Switch bluetooth on
#--------------------------------------------------------------------
# Search Utilities
#--------------------------------------------------------------------
# Find files modified in the last N minutes
elif [ "$function" == "find:recent" ]; then
echo "Searching for files modified in the last "$firstParameter" minutes..."
printf "${GREEN}sudo find / -mmin ${GRAY}${firstParameter}${GREEN} -type f\n\n${NC}"
sudo find / -mmin $firstParameter -type f
# Find duplicated files
elif [ "$function" == "find:duplicated" ]; then
# Check if fdupes is installed
if [ ! -f /usr/local/bin/fdupes ]; then
printf "${RED}fdupes not found ${NC}- ${GREEN}Installing dependency...\n\n${NC}"
printf "${GREEN}brew install fdupes\n\n${NC}"
brew install fdupes
echo "Searching for duplicated files in current directory and subdirectories..."
fdupes -r .
else
printf "${GREEN}fdupes -r .\n\n${NC}"
echo "Searching for duplicated files in current directory and subdirectories..."
fdupes -r .
fi
#--------------------------------------------------------------------
# Network Utilities
#--------------------------------------------------------------------
# Internet connection speed test
elif [ "$function" == "speedtest" ]; then
if [ ! -f /usr/local/lib/node_modules/speed-test/cli.js ]; then
read -r -p "Do you want to install the Speed Test utility? (https://github.com/sindresorhus/speed-test) (Yes / No)" response
case $response in
[yY][eE][sS]|[yY])
npm install --global speed-test
;;
*)
exit
;;
esac
else
echo "Testing internet connection speed..."
node "/usr/local/lib/node_modules/speed-test/cli.js"
fi
# Run internet connection Speed Test each 5 minutes
elif [ "$function" == "speedtest:infinite" ]; then
if [ ! -f /usr/local/lib/node_modules/speed-test/cli.js ]; then
read -r -p "Do you want to install the Speed Test utility? (https://github.com/sindresorhus/speed-test) (Yes / No)" response
case $response in
[yY][eE][sS]|[yY])
npm install --global speed-test
;;
*)
exit
;;
esac
else
while true
do
title="\nTesting internet connection speed - "
title+=`date '+%Y-%m-%d %H:%M:%S'`
echo $title
node "/usr/local/lib/node_modules/speed-test/cli.js"
sleep 300
done
fi
# List of used ports
elif [ "$function" == "ports" ]; then
echo "Getting list of used ports..."
printf "${GREEN}sudo lsof -iTCP -sTCP:LISTEN -P\n\n${NC}"
sudo lsof -iTCP -sTCP:LISTEN -P
# Get local IP address
elif [ "$function" == "ip:local" ]; then
local_ip=$(ipconfig getifaddr en0)
if [ $? == 0 ]; then
printf "${GREEN}ipconfig getifaddr en0\n\n${NC}"
else
printf "${GREEN}ipconfig getifaddr en1\n\n${NC}"
local_ip=$(ipconfig getifaddr en1)
fi
printf "Your IP address is:\n${local_ip}\n"
# Get public IP address
elif [ "$function" == "ip:public" ]; then
printf "${GREEN}wget http://ipinfo.io/ip -qO -\n\n${NC}"
wget http://ipinfo.io/ip -qO -
#--------------------------------------------------------------------
# LAMP (Linux, Apache, MySQL, PHP)
#--------------------------------------------------------------------
## MySQL Utilities
elif [ "$function" == "mysql" ]; then
printf "${GREEN}open -a /Applications/Sequel\ Pro.app\n\n${NC}"
open -a /Applications/Sequel\ Pro.app
elif [ "$function" == "mysql:cli" ]; then
printf "${GREEN}mycli ${GRAY}-u${mysql_user} -p${mysql_password} ${GREEN}-S /Applications/MAMP/tmp/mysql/mysql.sock\n\n${NC}"
mycli -u$mysql_user -p$mysql_password -S /Applications/MAMP/tmp/mysql/mysql.sock
elif [ "$function" == "mysql:export-all" ]; then
printf "${GREEN}open ${phpmyadmin}\n\n${NC}"
${mysqldump} -u ${mysql_user} -p ${mysql_password} --all-databases > all-database.sql
elif [ "$function" == "phpmyadmin" ]; then
printf "${GREEN}open ${phpmyadmin}\n\n${NC}"
open $phpmyadmin
# Export MySQL database
elif [ "$function" == "mysql:dump" ]; then
echo "Please enter the filename to save the compressed database: "
if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
read filename
if [ ! -z "$filename" -a "$filename" != " " ]; then
printf "${GREEN}$mysql --host=localhost ${GRAY}-u${mysql_user} -p${mysql_password}${GREEN} | pv | gzip -c > ${GRAY}'${filename}'.sql.gz\n\n${NC}"
$mysqldump -u"$mysql_user" -p"$mysql_password" $firstParameter | pv | gzip -c > "$filename".sql.gz
else
"Please specify the file name"
fi
else
echo "Please specify the database to export"
echo "E.g.: mysql:export database"
fi
# List all MySQL databases
elif [ "$function" == "mysql:list" ]; then
printf "${GREEN}echo 'show databases;' | ${mysql} ${GRAY} -u${mysql_user} -p${mysql_password} ${databasename}\n\n${NC}"
echo "show databases;" | ${mysql} -u${mysql_user} -p${mysql_password}
# Import MySQL database
elif [ "$function" == "mysql:import" ]; then
echo "Please enter the database name to import the selected SQL file: "
if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
read databasename
if [ ! -z "$databasename" -a "$databasename" != " " ]; then
printf "${GREEN}pv ${GRAY}${firstParameter}${GREEN} | ${mysql} ${GRAY} -u${mysql_user} -p${mysql_password} ${databasename}\n\n${NC}"
pv $firstParameter | $mysql -u"$mysql_user" -p"$mysql_password" $databasename
else
"Please specify the database name"
fi
else
echo "Please specify the SQL file to import"
echo "E.g.: mysql:import /path/to/file.sql"
fi
# Export all MySQL databases
elif [ "$function" == "mysql:dump-all" ]; then
databases=`$mysql -u"$mysql_user" -p"$mysql_password" -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db"
$mysqldump -u"$mysql_user" -p"$mysql_password" --databases $db > `date +%Y%m%d`.$db.sql
fi
done
# Import single MySQL database table