-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.bash_profile
3570 lines (3142 loc) · 115 KB
/
.bash_profile
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/bash
## Study REF-> https://explainshell.com/
## Study REF-> https://developer.apple.com/library/content/documentation/OpenSource/Conceptual/ShellScripting/performance/performance.html
## Study REF-> https://aadrake.com/command-line-tools-can-be-235x-faster-than-your-hadoop-cluster.html
###!/usr/local/bin/dash
## BASH VS DASH - https://www.jpsdomain.org/public/2008-JP_bash_vs_dash.pdf
##TODO: DASH PORTABILITY SUPPORT (For Loop -> While Loop)
#REF1: https://unix.stackexchange.com/questions/148035/is-dash-or-some-other-shell-faster-than-bash
#REF2: https://askubuntu.com/questions/621981/for-loop-syntax-in-shell-script
#REF3: https://wiki.archlinux.org/index.php/Dash
#REF4: https://lyness.io/the-functional-and-performance-differences-of-sed-awk-and-other-unix-parsing-utilities
#!/bin/sh
# number=0
# while [ $number -lt 10 ]
# do
# printf "\t%d" "$number"
# number=$((number + 1))
# done
# export LC_ALL=C
export LC_ALL=en_US.UTF-8
export LoginDay=$(date +%F)
## LC_ALL=en_US or C? To speed up in byte?
# https://unix.stackexchange.com/questions/303157/is-there-something-wrong-with-my-script-or-is-bash-much-slower-than-python/303167#303167
## Drawbacks
# $ LC_ALL=en_US sort <<< $'a\nb\nA\nB'
# a
# A
# b
# B
# $ LC_ALL=C sort <<< $'a\nb\nA\nB'
# A
# B
# a
# b
# Authors :
# [Ralic Lo ([email protected])
# [NATHANIEL LANDAU] https://natelandau.com/nathaniel-landau-resume/
# Copyright [2017]
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
### ./configure notes
#(3) When space is important, we suggest --without-readline, --disable-shared,
# and possibly --disable-nls and --disable-dynamic-loading.
#For MacOSX, install coreutils (which includes greadlink)
# $brew install coreutils
# CC C compiler command ## gcc
# CFLAGS C compiler flags
# CXX C++ compiler command ## gcc
# CXXFLAGS C++ compiler flags ## gcc-E
# CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir>
# LDFLAGS linker flags, e.g. -L<lib dir>
# LIBS libraries to pass to the linker, e.g. -l<library>
# CPP C preprocessor ## gcc -E
# CXXCPP C++ preprocessor
## TODO
# --with-cxxflags='-mmic ' \
# --with-cflags='-mmic '
# --flto-compression-level ## LTOFLAS Controls
# https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Optimize-Options.html
# MPIFLAG=" -lelan lmpi"
## Notes:
## change gcc to cc // 2017-06-08 ## change cc to mpicc //2017-09-07
## CXXCPP: 2017.9.12 -- Using g++7 ok, not ok using clang-5 or mpicpp"
## -- Other options : g++ -E or gcc -E
## -- It's ok to replace gcc c++ by gcc-7
### Defines commands to be excuted after parsing all scripts
### (For script Hoisting)
function START_UP@BEGIN() {
echo "[Info] Running boot scripts"
SETCC="gcc"
GCC_VER=7
alias xxargs='xargs -n 1 -P $PACORES'
alias sll=subl
}
START_UP@BEGIN
function START_UP@END() {
printlibs > /dev/null
bootlibs >/dev/null
setcc
cheditor vi > /dev/null
export MAKEJOBS="-j16"
alias cgrep="grep --color=always"
neofetch
# export LDFLAGS="-L/usr/local/Cellar/gcc/7.2.0/lib/gcc/7 $LDFLAGS"
# export CPPFLAGS="-I/usr/local/Cellar/gcc/7.2.0/lib/gcc/7/gcc/x86_64-apple-darwin17.0.0/7.2.0/include $CPPFLAGS"
# export CPPFLAGS="-I/usr/local/Cellar/gcc/7.2.0/include/c++/7.2.0/tr1 $CPPFLAGS"
# macdev
}
function setcc() {
if [[ $# -eq 1 ]] ; then
SETCC=$1
fi
case $SETCC in
"gcc") ## DEFAULT ##
export GCC_FLAGS=" -mmovbe -m128bit-long-double -msseregparm -mfpmath=sse+387 -mfpmath=both -lpthread"
FC="gfortran"; CC="gcc" ;CXX="gcc" ;
CPP="gcc -E" ; CXXCPP=" gcc -E" ;
;;
"gccx") ## GCC ##
#10/06 GCC ONLY? , these flags may further import program performance when we are using gcc-7, tested on Debian9/Xeon CPU ##
export GCC_FLAGS="-mmovbe -m128bit-long-double -msseregparm -mfpmath=sse+387 -mfpmath=both -lpthread"
FC="gfortran-$GCC_VER";CC="gcc-$GCC_VER";CXX="gcc-$GCC_VER" ;CPP="gcc-$GCC_VER -E";CXXCPP="gcc-$GCC_VER -E"
export HOMEBREW_CC="gcc-$GCC_VER"
;;
"clang") ## CLANG ##
FC="gfortran";CC="cc";CXX="cc" ;CPP="gcc -E";CXXCPP="gcc -E"
export HOMEBREW_CC="clang"
;;
"mpicc") ## MPICC version ##
FC="mpifort"; CC="mpicc"; CXX="mpicc" ; CPP="mpic++ -E " ;CXXCPP="mpicc -E"
MPIFC="mpifort";MPICC="mpicc";MPICPP="mpicc -E" ;MPICXX="mpicxx"
# FC="mpifort"; CC="mpicc"; CXX="mpicxx" ; CPP="mpicc -E" ;CXXCPP="clang -E"
# MPIFC="mpifort";MPICC="mpicc";MPICPP="mpicc -E" ;MPICXX="mpicxx"
HOMEBREW_CC="mpicc"; HOMEBREW_CXX="mpicxx"
;;
*) ## NO Setting as default ##
;;
esac
## echo with $'' strings = ANSI C Quoting:
echo "$(tput setaf 2)"$'[Info] setcc (gcc/gccx/clang/mpicc). To change compiler in BREW.
Type brew --env for details,SETCC='$SETCC',PACORES='$PACORES"$(tput sgr0)"
}
function cheditor() {
echo "[Info] cheditor, Script to change your default terminal editor"
if [[ $# -eq 0 ]] ; then
local VAR_EDITOR=subl
else
local VAR_EDITOR="$@"
fi
export TEXT_Editor=$VAR_EDITOR
export EDITOR=$VAR_EDITOR
}
# function checkOS() {
# }
# export HOMEBREW_BUILD_FROM_SOURCE=1
### For Linux/Debian
if [ "$(uname -s)" == "Linux" ]; then
## PARALLEL PROCESSING for lz4dir/xz4dir
PACORES=$(( $(grep -c ^processor /proc/cpuinfo) ))
PACORES=$(( $PACORES * 2 ))
if [[ $(uname -r) == *"amzn1"* ]]; then
echo " RUNNING AWS LINUX!"
setcc gcc
fi
UsrPATH="/home"
UsrNAME=$(whoami)
## Linuxbrew Support
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
export MANPATH="/home/linuxbrew/.linuxbrew/share/man:$MANPATH"
export INFOPATH="/home/linuxbrew/.linuxbrew/share/info:$INFOPATH"
#export MASTERUSER= $(whoami)
# sudo mkdir -p /home/linuxbrew
# sudo ln -s -f /home/linuxbrew/.linuxbrew/usr /usr/local/.linuxbrew
# sudo ln -s -f /home/linuxbrew/.linuxbrew/Cellar /usr/local/Cellar ## -f : force
# sudo ln -s -f /home/linuxbrew/.linuxbrew/Homebrew /usr/local/Homebrew ## -f : force
# sudo ln -s -f /home/linuxbrew/.linuxbrew/Homebrew/Library /usr/local/Library ## -f : force
# sudo ln -s -f /home/linuxbrew/.linuxbrew/opt /usr/local/opt ## -f : force
# sudo ln -s /home/linuxbrew/.linuxbrew/include /usr/local/include ## -f : force
# sudo find /usr/local -maxdepth 1 -type l | awk '{print "sudo chown -R $MASTERUSER "$1}' > chown.run;. chown.run
# f: Opens current directory in Linux Finder
alias f='xdg-open ./'
READLINK="readlink"
# JAVA_HOME="$OPT_PREFIX/jdk"
# export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre"
# LTOFLAGS="-flto" # -m32 # -m64
alias make="make $MAKEJOBS"
COLOR_FLAG="--color=auto"
export BREW_PREFIX="/home/linuxbrew/.linuxbrew"
fi
### For MacOS/Darwin
if [ "$(uname -s)" == "Darwin" ]; then
MACOSX_DEPLOYMENT_TARGET=$(sw_vers | grep ProductVersion | awk '{print $2}')
export MACOSX_DEPLOYMENT_TARGET="$MACOSX_DEPLOYMENT_TARGET"
# export MACOSX_DEPLOYMENT_TARGET=10.5
PACORES=$(sysctl hw | grep hw.ncpu | awk '{print $2}')
PACORES=$(( $PACORES * 2 ))
UsrPATH="/Users"
# f: Opens current directory in MacOS Finder
alias f='open -a Finder ./'
READLINK="greadlink"
system_VER=64
LTOFLAGS= # "-flto" #-m64" # -m32 -fopenmp -m64 -m32
JAVA_HOME=$(/usr/libexec/java_home)
# COLOR_FLAG="--color=auto"
export BREW_PREFIX="/usr/local"
alias make="gmake $MAKEJOBS"
alias uname="guname" ### To enable -o flag.
alias find="gfind" ## [Waring Ignored] gfind: invalid argument `-1d' to `-mtime'
alias time="gtime -v"
alias tar="gtar"
alias xargs="gxargs" ## Using GNU's xargs to enable -i feature.
# export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
# export JAVA6_HOME="/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
# export JAVA8_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre"
## Set default blocksize for ls, df, du
## IMPORTANT Check it by : diskutil info / | grep "Block Size"
export BLOCKSIZE=4096
fi
export OPT_PREFIX="$BREW_PREFIX/opt"
## Universal workspace for two or more versions of macOS development
alias apps='cd /Volumes/data/Applications'
alias linkapps='ln -s /Volumes/data/Applications $(pwd)/apps'
alias work='cd /Volumes/data/WorkSpace'
alias linkwork='ln -s /Volumes/data/WorkSpace $(pwd)/work'
alias bp3='python3 setup.py bdist > dist.log;python3 setup.py install'
# http://www.netlib.org/benchmark/hpl/results.html
#https://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/i386-and-x86_002d64-Options.html
### DANGER : -mo-align-double <--- This CPU flag may cause non-executable
# export CPUFLAGS="$GCC_FLAGS -msse2 -masm=intel -msse3 "
export MachineFLAGS="-mmmx -maes -msse -maes $LTOFLAGS $CPUFLAGS" #
export MATHFLAGS=" -ffast-math -fno-signed-zeros -ffp-contract=fast $MachineFLAGS "
### DEFAULT FLAGS SUPPORT
##http://www.netlib.org/benchmark/hpl/results.html #-isystem /usr/include
export CFLAGS="-Ofast -fomit-frame-pointer -funroll-loops $MATHFLAGS "
# -isystem $BREW_PREFIX/include ## RISKY CFLAGS
export CXXFLAGS="$MATHFLAGS "
export FFLAGS="$CFLAGS "
### set gcc debug flag, Default is not to use it.
# DEBUGFLAG="-g"
alias cpx="cc -c $LDFLAGS $DEBUGFLAG $CFLAGS -Ofast -flto"
export ARCHFLAGS="-march=native"
# -arch x86-64 -arch i386 -Xarch_x86_64
case $system_VER in
32)
export LDFLAGS="$LDFLAGS"
export FFLAGS="$FFLAGS"
export CFLAGS="$CFLAGS " #$ARCHFLAGS
export CPPFLAGS="$CPPFLAGS"
# export LD_LIBRARY_PATH="/Developer/SDKs/MacOSX.sdk/usr/lib/gcc/i686-apple-darwin11/4.2.1/:$LD_LIBRARY_PATH"
;;
64) #
export LDFLAGS="$LDFLAGS"
export FFLAGS="$FFLAGS"
export CFLAGS="$CFLAGS " #$ARCHFLAGS
export CPPFLAGS="$CPPFLAGS"
# export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/Developer/SDKs/MacOSX.sdk/usr/lib/gcc/i686-apple-darwin11/4.2.1/"
;;
*)
export LDFLAGS="$LDFLAGS"
export FFLAGS="$FFLAGS"
export CFLAGS="$CFLAGS $ARCHFLAGS"
export CPPFLAGS="$CPPFLAGS"
# export LD_LIBRARY_PATH="/usr/lib:$LD_LIBRARY_PATH"
;;
esac
## e2fslib support
# export PATH="$(brew --prefix e2fsprogs)/lib:$PATH"
## QT Support
## OpenCV3 Support
## CUDA SUPPORT ##
export PATH="/usr/local/cuda/bin:/usr/local/cuda/nvvm/bin:$PATH"
export LDFLAGS="-L/usr/local/cuda/lib -L/usr/local/cuda/nvvm/lib $LDFLAGS"
export CPPFLAGS="-I/usr/local/cuda/include -I/usr/local/cuda/nvvm/include $CPPFLAGS"
## graphviz support
## openblas support
## brew install openblas
export OPENBLAS_NUM_THREADS=32
## llvm support
## brew reinstall llvm -v --all-targets --rtti --shared --with-asan --with-clang --use-clang
# export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib $LDFLAGS"
# export CPPFLAGS="-I/usr/local/opt/llvm/include $CPPFLAGS"
# -I/usr/local/opt/llvm/include/c++/v1/ ## RISKY CPPFLAGS
export
## rJava Support
#R CMD javareconf JAVA_CPPFLAGS=-I/System/Library/Frameworks/JavaVM.framework/Headers
#R CMD javareconf JAVA_CPPFLAGS="-I/System/Library/Frameworks/JavaVM.framework/Headers -I$(/usr/libexec/java_home | grep -o '.*jdk')"
## Setting Locale
## locale
# https://www.gnu.org/savannah-checkouts/gnu/libc/manual/html_node/Locale-Categories.html
echo "________________________________________________________________________________"
uname -a
## Change CL to be colored for MAC
export CLICOLOR=1
export TERM="xterm-color"
## Python include/lib support
PYVM_VER=python3.6m ## python3.6dm for debug
CPPFLAGS="-I/usr/local/opt/python3/include/$PYVM_VER $CPPFLAGS"
LDFLAGS="-L/usr/local/opt/python3/lib $LDFLAGS"
CPPFLAGS="-I/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m $CPPFLAGS"
## GNU GCC support for OSX
## GNU GCC/ BINUTILS SUPPORT
## brew install binutils
# export PATH="$OPT_PREFIX/mingw-w64/bin:$PATH"
export MANPATH="$OPT_PREFIX/gnu-sed/libexec/gnuman:$MANPATH" ## man gsed for gnused
export MANPATH="$OPT_PREFIX/coreutils/libexec/gnuman:$MANPATH"
# export PATH="$OPT_PREFIX/coreutils/libexec/gnubin:$PATH"
## X11 Support
export PATH="/opt/X11/bin:$PATH"
export LDFLAGS="-L/opt/X11/lib $LDFLAGS"
export CPPFLAGS="-I$/opt/X11/include $CPPFLAGS"
## Android / Java src code Support
# export PATH="$OPT_PREFIX/dex2jar/bin:$PATH"
## Rstudio Support
## brew install rstudio
export PATH="/Applications/RStudio.app/Contents/MacOS:$PATH"
## QT Setup
export PATH="$OPT_PREFIX/qt/bin:$PATH"
## MAC Developer Commandline Support
export PATH="/Library/Developer/CommandLineTools/usr/bin:$PATH"
##SWIFT SUPPORT
export PATH="/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH"
# TOMEE-PLUS
# export PATH="$PATH:$OPT_PREFIX/tomee-plus/libexec/bin"
# Node.js support
# REF: https://nodesource.com/blog/configuring-your-npmrc-for-an-optimal-node-js-environment/
export PATH="~/work/.npm/bin:$PATH"
# Android support on MAC
export ANDROID_HOME=~/Library/Android/sdk
export PATH=$PATH:~/Library/Android/sdk/platform-tools
#android toolbox binary excutable
export PATH=$PATH:~/Library/Android/sdk/tools
# Golang support / Blueprint Support # https://blue-jay.github.io/
# export JAYCONFIG=./env.json
export JAYCONFIG=$HOME/golang/bluejay_env.json
#/usr/local/go/bin
export GOPATH"=$HOME/golang"
export GOROOT="$OPT_PREFIX/go/libexec"
export PATH="$PATH:$GOPATH/bin"
export PATH="$PATH:$GOROOT/bin"
# scala support in Intellij
export SCALA_HOME=$OPT_PREFIX/scala/idea
# Apache Spark Support start-master.sh
# http://spark.apache.org/docs/latest/spark-standalone.html
# export PYTHONPATH=$PYTHONPATH:$SPARK_HOME/python:$SPARK_HOME/python/build
# export PYTHONPATH=/usr/local/lib/python3.6/site-packages
# export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
alias pip3="export PYTHONPATH=/usr/local/lib/python3.6/site-packages;pip3"
alias pypath3="export PYTHONPATH=/usr/local/lib/python3.6/site-packages"
alias pypath2="export PYTHONPATH=/usr/local/lib/python2.7/site-packages"
alias xpath="echo /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/"
SPARK_HOME="$OPT_PREFIX/apache-spark/libexec"
export PYSPARK_DRIVER_PYTHON=python3
# export PYSPARK_DRIVER_PYTHON_OPTS=notebook
export PATH="$PATH:$SPARK_HOME"
export PATH="$PATH:$OPT_PREFIX/apache-spark/libexec/sbin"
## Jupyter Notebook Support
# export PYTHONPATH=$SPARK_HOME/python/lib/py4j-0.10.4-src.zip:$PYTHONPATH
# Mysql Support
# alias mysql=/usr/local/mysql/bin/mysql
# alias mysqladmin=/usr/local/mysql/bin/mysqladmin
export PATH="$PATH:/usr/local/mysql/bin:$CASSANDRA_HOME/bin:$FORREST_HOME/bin"
# Tensorflow support on Mac OS X
# export TF_BINARY_URL=
# https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.3.0-py2-none-any.whl
# export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl
# https://pypi.python.org/packages/4f/8e/8f036b718c97b7a2a96f4e23fbaa55771686efaa97a56579df8d6826f7c5/tensorflow-1.3.0-cp36-cp36m-macosx_10_11_x86_64.whl
VG_TMPDIR=~/.tmp/openmpi ## For valgrind
TMPDIR=~/.tmp/openmpi
BOOST_ROOT="/usr/local/opt/boost"
OpenMP_C_FLAGS=$CFLAGS
OpenMP_C_LIB_NAMES=
GNUTLS_CFLAGS=$CFLAGS
## Kubenate Support
# source $(brew --prefix)/etc/bash_completion
# source <(kubectl completion bash)
# [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
# 6. Networking
# 7. System Operations & Information
# 8. Web Development
# 9. Reminders & Notes
#
# ---------------------------------------------------------------------------
# -------------------------------
# 1. ENVIRONMENT CONFIGURATION
# -------------------------------
# Change Prompt
# ------------------------------------------------------------
# if [ $0 = "dash" ]; then
USER=$(id -un)
HOSTNAME=$(uname -n)
export PS1='________________________________________________________________________________
$(tput bold 6)$PWD $(tput setaf 6)@$HOSTNAME $(tput setaf 4)($USER)$(tput sgr0)
=>'
export SUDO_PS=$PS1
#fi
# Add color to terminal
# (this is all commented out as I use Mac Terminal Profiles)
# from http://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/
# ------------------------------------------------------------
# export CLICOLOR=1
# export LSCOLORS=ExFxBxDxCxegedabagacad
# -----------------------------
# 2. MAKE TERMINAL BETTER
# -----------------------------
# alias gtime='/usr/local/opt/gnu-time/bin/time'
# alias gmake='/usr/local/opt/make/bin/gmake'
alias cp='cp -iv' # Preferred 'cp' implementation
alias mv='mv -iv' # Preferred 'mv' implementation
alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation
alias ls="ls $COLOR_FLAG" # Ensure ls will display color
alias ll='ls -FGlAhp $COLOR_FLAG' # Preferred 'ls' implementation
alias sofu="du -d 1 * | sort -n -k1" ## Sort file using du , accending , --max-depth means -d
cd() { prevfolder=$(pwd);builtin cd "$@"; ll; } # Always list directory contents upon 'cd'
termfolder=$(pwd);
alias orig='cd $termfolder' ## Quick return to terminal-login folder
alias prev='cd $prevfolder' ## prev -- Quick switching between two folders. 2017/07/30
alias less='less -FSRXc' # Preferred 'less' implementation
alias cd..='cd ../' # Go back 1 directory level (for fast typers)
alias ..='cd ../' # Go back 1 directory level
alias ...='cd ../../' # Go back 2 directory levels
alias .3='cd ../../../' # Go back 3 directory levels
alias .4='cd ../../../../' # Go back 4 directory levels
alias .5='cd ../../../../../' # Go back 5 directory levels
alias .6='cd ../../../../../../' # Go back 6 directory levels
alias edit='/usr/bin/vi' # edit: Opens any file in sublime editor
alias ~="cd ~" # ~: Go Home
alias c='clear' # c: Clear terminal display
alias wwich='type -all' # wwich: Find executables
alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths
alias show_options='shopt' # Show_options: display bash options settings
alias fix_stty='stty sane' # fix_stty: Restore terminal settings when screwed up
alias cic='set completion-ignore-case On' # cic: Make tab-completion case-insensitive
mcd () { mkdir -p "$1" && cd "$1"; } # mcd: Makes new Dir and jumps inside
trash () { command mv "$@" ~/.Trash ; } # trash: Moves a file to the MacOS trash
ql () { qlmanage -p "$*" >& /dev/null; } # ql: Opens any file in MacOS Quicklook Preview
alias DT='tee ~/Desktop/terminalOut.txt' # DT: Pipe content to file on MacOS Desktop
# lr: Full Recursive Directory Listing
# ------------------------------------------
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less'
# mans: Search manpage given in agument '1' for term given in argument '2' (case insensitive)
# displays paginated result with colored search terms and two lines surrounding each hit. Example: mans mplayer codec
# --------------------------------------------------------------------
mans () {
man $1 | grep -iC2 --color=always $2 | less
}
# showa: to remind yourself of an alias (given some part of it)
# ------------------------------------------------------------
showa () { /usr/bin/grep --color=always -i -a1 $@ ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; }
# -------------------------------
# 3. FILE AND FOLDER MANAGEMENT
# -------------------------------
# to create a file of a given size: /usr/sbin/mkfile or /usr/bin/hdiutil
# ---------------------------------------
# e.g.: mkfile 10m 10MB.dat
# e.g.: hdiutil create -size 10m 10MB.dmg
# the above create files that are almost all zeros - if random bytes are desired
# then use: ~/Dev/Perl/randBytes 1048576 > 10MB.dat
alias nofiles='echo "Total files in directory:" $(ls -1 | wc -l)' # numFiles: Count of non-hidden files in current dir
alias make1mb='mkfile 1m ./1MB.dat' # make1mb: Creates a file of 1mb size (all zeros)
alias make5mb='mkfile 5m ./5MB.dat' # make5mb: Creates a file of 5mb size (all zeros)
alias make10mb='mkfile 10m ./10MB.dat' # make10mb: Creates a file of 10mb size (all zeros)
alias fsize="find . -type f -ls -printf '\0' | sort -zk7rn | tr -d '\0'" ## fsize : find and sort file size, accending
# cdf: 'Cd's to frontmost window of MacOS Finder
# ------------------------------------------------------
cdf () {
currFolderPath=$( /usr/bin/osascript <<EOT
tell application "Finder"
try
set currFolder to (folder of the front window as alias)
on error
set currFolder to (path to desktop folder as alias)
end try
POSIX path of currFolder
end tell
EOT
)
echo "cd to \"$currFolderPath\""
cd "$currFolderPath"
}
# extract: Extract most know archives with one command
# https://www.systutorials.com/docs/linux/man/1-lz4/
# ---------------------------------------------------------
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.lz4) unlz4dir $1 ;;
*.tar.xz) tar xf $1 ;;
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.xz) xz -d $1 ;;
*.7z) 7z x $1 ;;
*.lz4) unlz4 $1 ;;
*.lzma) tar --lzma -xvf f $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# ---------------------------
# 4. SEARCHING
# ---------------------------
alias qfind="find . -name " # qfind: Quickly search for file
function ff () { find . -name "$@" ; } # ff: Find file under the current directory
function ffs () { find . -name "$@"'*' ; } # ffs: Find file whose name starts with a given string
function ffe () { find . -name '*'"$@" ; } # ffe: Find file whose name ends with a given string
function gftype() {
echo "[Info] This support you to grep certian filename suffix"
echo "[Usage] 'find . | gftype log' to find all *.log"
grep ".*\."$1"$"
}
function findcp() {
echo "[Info] findmv, Generate a script for copy ONLY files in CURRENT folder to another folder"
echo "args1 : new folder name"
echo '[Question] Starts ? (yes / others for skip)'
read option
case $option in
yes)
find . -maxdepth 1 -type f -print0 | ffilter | xargs -n 1 -P $PACORES -0 -I'{}' cp '{}' $1
;;
*)
echo "find . -maxdepth 1 -type f -print0 | ffilter | xargs -n 1 -P $PACORES -0 -I'{}' cp '{}' $1"
;;
esac
}
# spotlight: Search for a file using MacOS Spotlight's metadata
# -----------------------------------------------------------
spotlight () { mdfind "kMDItemDisplayName == '$@'wc"; }
# ---------------------------
# 5. PROCESS MANAGEMENT
# ---------------------------
# findpid: find out the pid of a specified process
# -----------------------------------------------------
# Note that the command name can be specified via a regex
# E.g. findPid '/d$/' finds pids of all processes with names ending in 'd'
# Without the 'sudo' it will only find processes of the current user
# Example : findpid bash
# -----------------------------------------------------
alias findpid="lsof -t -c"
## This script helps you find out the pid of a process on specific port
## Example : portid 80
function portid () {
sport="$@"
lsof -i:$sport
echo "------"
echo "Port:"$sport",PID=" $(lsof -i:$sport | grep $(whoami) | awk '{print $2}');
}
# function ppid() {
# echo $! >test.pid | cat test.pid
# }
# memHogsTop, memHogsPs: Find memory hogs
# -----------------------------------------------------
alias memHogsTop='top -l 1 -o rsize | head -20'
alias memHogsPs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'
# cpuHogs: Find CPU hogs
# -----------------------------------------------------
alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'
# topForever: Continual 'top' listing (every 10 seconds)
# -----------------------------------------------------
alias topForever='top -l 9999999 -s 10 -o cpu'
# ttop: Recommended 'top' invocation to minimize resources
# ------------------------------------------------------------
# Taken from this macosxhints article
# http://www.macosxhints.com/article.php?story=20060816123853639
# ------------------------------------------------------------
alias ttop="top -R -F -s 10 -o rsize"
# myps: List processes owned by my user:
# ------------------------------------------------------------
function myps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }
# ---------------------------
# 6. NETWORKING
# ---------------------------
alias servall='sudo kill $(lsof -t -i:80,443,8080)&& echo "Killed processs on 80,443,8080"' # Reset all Http ports
alias netconns='lsof -i' # netCons: Show all open TCP/IP sockets
alias flushDNS='dscacheutil -flushcache' # flushDNS: Flush out the DNS Cache
alias lsock='sudo /usr/sbin/lsof -i -P' # lsock: Display open sockets
alias lsockU='sudo /usr/sbin/lsof -nP | grep UDP' # lsockU: Display only open UDP sockets
alias lsockT='sudo /usr/sbin/lsof -nP | grep TCP' # lsockT: Display only open TCP sockets
alias ipInfo0='ipconfig getpacket en0' # ipInfo0: Get info on connections for en0
alias ipInfo1='ipconfig getpacket en1' # ipInfo1: Get info on connections for en1
alias openPorts='sudo lsof -i | grep LISTEN' # openPorts: All listening connections
alias showBlocked='sudo ipfw list' # showBlocked: All ipfw rules inc/ blocked IPs
# ii: display useful host related informaton
# -------------------------------------------------------------------
ii() {
echo -e "\nYou are logged on ${RED}$HOST"
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Current network location :$NC " ; scselect
echo -e "\n${RED}Public facing IP Address :$NC " ;myip
echo -e "\n${RED}DNS Configuration:$NC " ; scutil --dns
echo
}
# ---------------------------------------
# 7. SYSTEMS OPERATIONS & INFORMATION
# ---------------------------------------
alias mountReadWrite='/sbin/mount -uw /' # mountReadWrite: For use when booted into single-user
# cleanupDS: Recursively delete .DS_Store files
# -------------------------------------------------------------------
alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"
# finderShowHidden: Show hidden files in Finder
# finderHideHidden: Hide hidden files in Finder
# -------------------------------------------------------------------
alias finderShowHidden='defaults write com.apple.finder ShowAllFiles TRUE'
alias finderHideHidden='defaults write com.apple.finder ShowAllFiles FALSE'
# cleanupLS: Clean up LaunchServices to remove duplicates in the "Open With" menu
# -----------------------------------------------------------------------------------
alias cleanupLS="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
# screensaverDesktop: Run a screensaver on the Desktop
# -----------------------------------------------------------------------------------
alias screensaverDesktop='/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background'
# ---------------------------------------
# 8. WEB DEVELOPMENT
# ---------------------------------------
alias apacheEdit='sudo edit /etc/httpd/httpd.conf' # apacheEdit: Edit httpd.conf
alias apacheRestart='sudo apachectl graceful' # apacheRestart: Restart Apache
alias editHosts='sudo edit /etc/hosts' # editHosts: Edit /etc/hosts file
alias herr='tail /var/log/httpd/error_log' # herr: Tails HTTP error logs
alias apacheLogs="less +F /var/log/apache2/error_log" # Apachelogs: Shows apache error logs
# httpHeaders: Grabs headers from web page
# example : httpHeaders www.google.com
alias httpHeaders="/usr/bin/curl -I -L"
# httpDebug: Download a web page and show info on what took time
function httpDebug () { /usr/bin/curl $@ -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\n" ; }
# ---------------------------------------
# 9. REMINDERS & NOTES
# ---------------------------------------
# remove_disk: spin down unneeded disk
# ---------------------------------------
# diskutil eject /dev/disk1s3
# to change the password on an encrypted disk image:
# ---------------------------------------
# hdiutil chpass /path/to/the/diskimage
# to mount a read-only disk image as read-write:
# ---------------------------------------
# hdiutil attach example.dmg -shadow /tmp/example.shadow -noverify
# mounting a removable drive (of type msdos or hfs)
# ---------------------------------------
# mkdir /Volumes/Foo
# ls /dev/disk* to find out the device to use in the mount command)
# mount -t msdos /dev/disk1s1 /Volumes/Foo
# mount -t hfs /dev/disk1s1 /Volumes/Foo
##### Dropbox_shell integration #####
#Looking for dropbox uploader
# if [ -f "./dup.sh" ]; then
# DU="./dup.sh"
# else
# DU=$(which dup.sh)
# if [ $? -ne 0 ]; then
# echo "Dropbox Uploader not found!"
# return 1
# fi
# fi
DU=/usr/local/bin/dup.sh
SHELL_HISTORY=~/.dropshell_history ## .dropbox_uploader
DU_OPT="-q"
DU_VERSION="0.2"
umask 077
#Dependencies check
# BIN_DEPS="id $READLINK ls basename ls pwd cut"
# for i in $BIN_DEPS; do
# which $i > /dev/null
# if [ $? -ne 0 ]; then
# echo -e "Error: Required program could not be found: $i"
# return 1
# fi
# done
#Check DropBox Uploader
if [ ! -f "$DU" ] ; then
echo "Dropbox Uploader not found: $DU"
echo "Please change the 'DU' variable according to the Dropbox Uploader location."
else
DU=$($READLINK -m "$DU")
fi
alias normalize_path="$READLINK -m"
################
#### START ####
################
history -r "$SHELL_HISTORY"
username=$(id -nu) ## or $(whoami)
#Initial Working Directory
function dls {
local arg1=$1
#Listing current dir
if [ -z "$arg1" ]; then
"$DU" $DU_OPT list "$CWD"
#Listing $arg1
else
#Relative or absolute path?
if [ ${arg1:0:1} == "/" ]; then
"$DU" $DU_OPT list "$(normalize_path "$arg1")"
else
"$DU" $DU_OPT list "$(normalize_path "$CWD/$arg1")"
fi
#Checking for errors
if [ $? -ne 0 ]; then
echo -e "ls: cannot access '$arg1': No such file or directory"
fi
fi
}
function dcd {
local arg1=$1
OLD_CWD=$CWD
if [ -z "$arg1" ]; then
CWD="/"
elif [ ${arg1:0:1} == "/" ]; then
CWD=$arg1
else
CWD=$(normalize_path "$OLD_CWD/$arg1/")
fi
"$DU" $DU_OPT list "$CWD" > /dev/null
#Checking for errors
if [ $? -ne 0 ]; then
echo -e "cd: $arg1: No such file or directory"
CWD=$OLD_CWD
fi
}
function dget {
local arg1=$1
local arg2=$2
if [ ! -z "$arg1" ]; then
#Relative or absolute path?
if [ ${arg1:0:1} == "/" ]; then
"$DU" $DU_OPT download "$(normalize_path "$arg1")" "$arg2"
else
"$DU" $DU_OPT download "$(normalize_path "$CWD/$arg1")" "$arg2"
fi
#Checking for errors
if [ $? -ne 0 ]; then
echo -e "get: Download error"
fi
#args error
else
echo -e "get: missing operand"
echo -e "syntax: get <FILE/DIR> [LOCAL_FILE/DIR]"
fi
}
function dput {
local arg1=$1
local arg2=$2
if [ ! -z "$arg1" ]; then
#Relative or absolute path?
if [ "${arg2:0:1}" == "/" ]; then
"$DU" $DU_OPT upload "$arg1" "$(normalize_path "$arg2")"
else
"$DU" $DU_OPT upload "$arg1" "$(normalize_path "$CWD/$arg2")"
fi
#Checking for errors
if [ $? -ne 0 ]; then
echo -e "put: Upload error"
fi
#args error
else
echo -e "put: missing operand"
echo -e "syntax: put <FILE/DIR> <REMOTE_FILE/DIR>"
fi
}
function drm
{
local arg1=$1
if [ ! -z "$arg1" ]; then
#Relative or absolute path?
if [ ${arg1:0:1} == "/" ]; then
"$DU" $DU_OPT remove "$(normalize_path "$arg1")"
else
"$DU" $DU_OPT remove "$(normalize_path "$CWD/$arg1")"
fi
#Checking for errors
if [ $? -ne 0 ]; then
echo -e "rm: cannot remove '$arg1'"
fi
#args error
else
echo -e "rm: missing operand"
echo -e "syntax: rm <FILE/DIR>"
fi
}
function dmkdir
{
local arg1=$1
if [ ! -z "$arg1" ]; then
#Relative or absolute path?
if [ ${arg1:0:1} == "/" ]; then
"$DU" $DU_OPT mkdir "$(normalize_path "$arg1")"
else
"$DU" $DU_OPT mkdir "$(normalize_path "$CWD/$arg1")"
fi
#Checking for errors
if [ $? -ne 0 ]; then
echo -e "mkdir: cannot create directory '$arg1'"
fi
#args error
else
echo -e "mkdir: missing operand"
echo -e "syntax: mkdir <DIR_NAME>"
fi
}
function dmv
{
local arg1=$1
local arg2=$2
if [ ! -z "$arg1" -a ! -z "$arg2" ]; then
#SRC relative or absolute path?
if [ ${arg1:0:1} == "/" ]; then
SRC="$arg1"
else
SRC="$CWD/$arg1"
fi
#DST relative or absolute path?
if [ ${arg2:0:1} == "/" ]; then
DST="$arg2"
else
DST="$CWD/$arg2"
fi
"$DU" $DU_OPT move "$(normalize_path "$SRC")" "$(normalize_path "$DST")"
#Checking for errors
if [ $? -ne 0 ]; then
echo -e "mv: cannot move '$arg1' to '$arg2'"
fi
#args error
else
echo -e "mv: missing operand"
echo -e "syntax: mv <FILE/DIR> <DEST_FILE/DIR>"
fi
}
function dcp
{
local arg1=$1
local arg2=$2
if [ ! -z "$arg1" -a ! -z "$arg2" ]; then
#SRC relative or absolute path?
if [ ${arg1:0:1} == "/" ]; then
SRC="$arg1"
else
SRC="$CWD/$arg1"
fi
#DST relative or absolute path?
if [ ${arg2:0:1} == "/" ]; then
DST="$arg2"
else
DST="$CWD/$arg2"
fi
"$DU" $DU_OPT copy "$(normalize_path "$SRC")" "$(normalize_path "$DST")"
#Checking for errors
if [ $? -ne 0 ]; then
echo -e "cp: cannot copy '$arg1' to '$arg2'"
fi