-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
executable file
·878 lines (853 loc) · 26.6 KB
/
.bashrc
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
#!/bin/bash
### If bash does not exist, return{{{
[ -z "$BASH" ] && return
[ -z "$PS1" ] && return
#}}}
### source system wide aliases{{{
if [ -f /etc/bashrc ]; then
source /etc/bashrc
fi
#}}}
### hostname (long style{{{
__uname=`uname`
if [ "$__uname" = 'Darwin' ] ; then
cmd_hostname="scutil --get LocalHostName"
elif [ "$__uname" = "FreeBSD" ] ; then
cmd_hostname="hostname"
elif [ "$__uname" = "Linux" ] ; then
cmd_hostname="hostname -f" # linux style
fi
__hostname=`$cmd_hostname`
if [ -z "$__hostname" ] ; then
echo ">> error: hostname is not set!!!" 1>&2
fi
# }}}
### reset env variables{{{
[ -z "$LD_LIBRARY_PATH" ] && export LD_LIBRARY_PATH=""
[ -z "$DYLD_LIBRARY_PATH" ] && export DYLD_LIBRARY_PATH=""
[ -z "$CPATH" ] && export CPATH=""
[ -z "$LIBRARY_PATH" ] && export LIBRARY_PATH=""
#}}}
### Internet access{{{
{
__is_interface_active() {
if [ "$__uname" = 'Darwin' ] ; then
local is="`ifconfig -u $1 | grep 'status: active'`"
else
local is="`ifconfig $1 2>/dev/null `"
fi
if [ "$is" ] ; then
return 0 # possible to access internet
else
return 1 # impossible to access internet
fi
unset -v $is
}
__is_net() {
while [ -n "$1" ]
do
__is_interface_active "$1"
if [ $? -eq 0 ] ; then
return 0 # possible
fi
shift
done
return 1 # impossible
}
# NOTE: xargs command use a defined function so thant it is need to export
# the function.
ifconfig | grep 'associated\|active' 1>/dev/null 2>/dev/null
export IS_INTERNET_ACTIVE=$?
if [ $IS_INTERNET_ACTIVE -eq 0 ] ; then
echo ">> possible to access to internet!!"
else
echo ">> impossible to access to internet :("
fi
unset -f __is_interface_active
unset -f __is_net
}
#}}}
### stty / options {{{
stty sane # reset all option to reasonable value
stty -ixon -ixoff # ctrl+s, ctrl+qの無効化
# if [ "$__uname" != 'Darwin' ] && [ -z "`stty | grep erase`" ] ; then
# # If a escape sequence which deletes a charactor is not set correctly, the
# # sequence is set to
# stty erase
# fi
[ -x "`which tabs`" ] && tabs -2 # tab width
set -o vi
#}}}
### language{{{
# NOTE: To check avaliable font list with `local -a | grep "ja"`
if [ "$__hostname" = 'kirara' ] ; then
# NOTE: I think it is not cool for terminal hacker to use Japanese, so that
# I use English.
# export LANG='ja_JP.UTF-8'
# export LC_ALL='ja_JP.UTF-8'
# export LANG='en_US.UTF-8'
# export LC_ALL='en_US.UTF-8'
:
elif [ "$__uname" = "FreeBSD" ] ; then
# export LANG=ja_JP.SJIS
# export LC_ALL=ja_JP.SJIS
# export LANG=ja_JP.eucJP
# export LC_ALL=ja_JP.eucJP
:
else
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
fi
#}}}
### alias{{{
alias ls='ls -G'
alias ll='ls -hlF'
alias la='ls -aF'
# alias l='ls -CF'
alias li='ls -1F'
alias his='history'
alias where='which'
alias mkdri='mkdir'
alias sl='ls'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias v='vi'
alias gpp='g++'
alias RM='rm -f'
alias rm='rm -i'
alias CP='cp -f'
alias cp='cp -i'
alias mv='mv -i'
alias today='date'
export DATE=`date +%Y%m%d`
alias update_date='export DATE=`date +%Y%m%d`' # year month day
alias update_time='export TIME=`date +%s`'
alias bash_keybind="bind -p | grep 'C-' | grep -v 'abort\|version\|accept' | less"
alias ducks='du -h -d 1'
if [ "$__uname" != 'Darwin' ] && [ -x "`which xdg-open`" ] ; then
# NOTE: On the Darwin, `open` is supported in default
alias open='xdg-open'
fi
if [ -x "`which tmux`" ] ; then
alias tmux='tmux -2'
alias ta='tmux a'
alias tat='tmux a -t'
fi
if [ "$__uname" = 'Darwin' ] ; then
TRASH_DIR="$HOME/.Trash/"
function trash () {
mv $* $TRASH_DIR
}
fi
#}}}
### tmux#{{{
if [ "$__uname" = "Darwin" ] ; then
ln -sf ~/.tmux.mac.conf ~/.tmux.conf
else
ln -sf ~/.tmux.noplugin.conf ~/.tmux.conf
fi
#}}}
### GNU Screen#{{{
if [ -x "`which screen`" ] ; then
# The alias is the meant that if there is no available session, create new
# session, else attach a most recently session.
alias scr='screen -D -RR'
fi
# Creating directory to manage the screen sesison, to avoid a error such
# impossible to create session file beacase of permission.
export SCREENDIR=$HOME/.screen/$__hostname
if [ ! -d "$SCREENDIR" ] ; then
mkdir -p $SCREENDIR
chmod 700 $SCREENDIR
fi
#}}}
### utiles{{{
# [ -s ${HOME}/tmp/bash/fpath.sh ] && \
# . $HOME/tmp/bash/fpath.sh ## get full path func
# [ -s ${HOME}/tmp/bash/prand.sh ] && \
# . $HOME/tmp/bash/prand.sh ## print random charactors
# [ -s ${HOME}/tmp/bash/makeMakefile.sh ] && \
# . $HOME/tmp/bash/makeMakefile.sh ## create template files for c lang
[ -s ${HOME}/tmp/kancolle/utils/kancolle_logbook.sh ] && \
. $HOME/tmp/kancolle/utils/kancolle_logbook.sh ## kancolle logbook
# if [ "`which find`" ] && [ "`which xargs`" ] && [ "`which egrep`" ] ; then
# fgx() {
# __search_path=$1 && shift
# __filetype=$1 && shift
# __filename=$1 && shift
# __regex=$1
# find $__search_path -type $__filetype -name "$__filename" | \
# xargs -I% egrep -H "$__regex" %
# }
# fi
# Function printing the battery status
if [ "$__uname" = 'FreeBSD' ] ; then
_print_battery_status () {
if [ "$1" != '-o' ] ; then
acpiconf -i 0
return 0
fi
acpiconf -i 0 | tail -n4 | head -n1 | awk '{print $3}'
}
elif [ "$__uname" = 'Darwin' ] ; then
_print_battery_status () {
pmset -g ps | egrep -o "[0-9]{1,3}%"
}
fi
#}}}
### autoextract {{{
# complete -W "vim study php html cake" cake # cake???????????????
[ -x "`which autoextract`" ] && \
complete -d autoextract # ~/bin/autoextrac?????????
#}}}
### environments{{{
export PAGER='less'
export SVN_SSH='ssh -q'
export DAY=`date +%d` # month day
export MONTH=`date +%B` # month in literal
export YEAR=`date +%Y` # year
export MEMO_PATH=${HOME}/.memo
#}}}
### console style{{{
if [ "$__uname" = "Darwin" ] || [ "$__uname" = "FreeBSD" ] ; then
export PS1='($(_print_battery_status)) \u@\h:\W\$ '
else
export PS1='\u@\h:\W\$ '
fi
if [ "`echo $TERM | grep 'screen'`" != "" ]; then
export PROMPT_COMMAND='pwd=`pwd`; echo -ne "\033k\033\0134\033k`basename $pwd`\033\\";share_history'
else
export PROMPT_COMMAND='share_history'
fi
share_history() {
history -a
history -c
history -r
update_time
}
export HISTCONTROL=ignoredups
export HISTFILE=$HOME/.bash_history
export HISTIGNORE="cd:pwd:fg*:bg*"
shopt -u histappend
export HISTSIZE=10000
## Current command name as window name
#export PS1='\[\033k\033\\\][\u@\h \W]\$ '
#export PS1='\[\033k\033\\\]\u@\h:\W\$ '
## PWD as window name
#export PS1='\u@\h:\W\$ '
#export PROMPT_COMMAND='echo -ne "\033k$(basename $(pwd))\033\\"'
## PWD when no command is running, otherwise current command name as window name
#export PS1='\u@\h:\W\$ '
#export PROMPT_COMMAND='echo -ne "\033k\033\0134\033k$(basename $(pwd))\033\\"'
## Above with a shared history among all terminals
#}}}
### shopt{{{
# shopt -s cdspell
# shopt -s extglob
# shopt -s histreedit
# shopt -s no_empty_cmd_completion
#}}}
### ls color{{{
if [ "$__uname" = "Linux" ]; then
alias ls='ls -NF --show-control-chars'
# if you use color ls, comment out above line and uncomment below 2 lines.
LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.i386.rpm=01;31:*.src.rpm=01;30:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.png=01;35:' ; export LS_COLORS
alias ls='ls --color=auto -NF --show-control-chars'
elif [ "$__uname" = 'FreeBSD' ]; then
export LSCOLORS=gxfxcxdxbxegedabagacad
alias ls='ls -G'
fi
#}}}
### rbenv{{{
export RUBYGEMS_GEMDEPS=
[ -d $HOME/.rbenv ] &&
export PATH=$HOME/.rbenv:$PATH
if [ -x "`which rbenv`" ] ; then
export RBENV_ROOT=`rbenv root`
echo "RBENV_ROOT: $RBENV_ROOT"
eval "`rbenv init -`"
fi
#}}}
### user commands {{{
# [ "$__uname" = "Linux" ] && [ "`uname -a | grep 'x86_64'`" ] && \
# [ -d $HOME/.usr/local/linux_x64/bin ] && \
# export PATH=$HOME/.usr/local/linux_x64/bin:$PATH
[ "$__uname" = "FreeBSD" ] && [ -z "`uname -a | grep 'x86_64'`" ] && \
[ -d $HOME/.usr/local/freebsd_386 ] && \
export PATH=$HOME/.usr/local/freebsd_386/bin:$PATH
[ "$__uname" = "Linux" ] && [ -d $HOME/.usr/bin ] && \
export PATH=$HOME/.usr/bin:$PATH
[ "$__uname" = "FreeBSD" ] && [ -d $HOME/usr/bin ] && \
export PATH=$HOME/usr/bin:$PATH
[ "$__uname" = "Linux" ] && [ -d $HOME/bin/centos ] && \
export PATH=$HOME/bin/centos:$PATH
if [ -f "/etc/redhat-release" ] ; then
__arr=( `cat /etc/redhat-release | cut -d' ' -f3 | tr -s '.' ' '` )
if [ ${__arr[0]} -eq 6 ] ; then
export PATH=$HOME/.usr/local/cent69/usr/bin:$PATH
export PATH=$HOME/.usr/local/cent6/usr/bin:$PATH
fi
unset -v __arr
fi
function _check_and_add_path () {
[ -d "$1" ] && export PATH="$1:$PATH"
}
_check_and_add_path "/usr/local/sbin"
_check_and_add_path "/usr/local/share/app/flutter/bin"
_check_and_add_path "$HOME/.local/bin"
_check_and_add_path "$HOME/bin"
_check_and_add_path "/usr/local/opt/gettext/bin"
_check_and_add_path "$HOME/Library/Python/2.7/bin"
_check_and_add_path "$HOME/Library/Python/3.6/bin"
_check_and_add_path "$HOME/.rvm/bin"
_check_and_add_path "$HOME/Library/Android/sdk/platform-tools"
_check_and_add_path "$HOME/Library/Android/sdk/tools"
_check_and_add_path "$HOME/Library/Android/sdk/ndk-bundle"
_check_and_add_path "$HOME/Work/Tools/dmmgw_util"
_check_and_add_path "$HOME/Work/Tools/onefetch/target/release"
_check_and_add_path "$HOME/.bin"
_check_and_add_path "/usr/local/texlive/2015/bin/x86_64-darwin"
_check_and_add_path "/usr/local/wine/bin"
_check_and_add_path "$HOME/tmp/utils/bin"
_check_and_add_path "$HOME/tmp/kancolle/utils/macosx-x64-ex.2.3.4"
_check_and_add_path "$HOME/Work/gist-dmm/slack-msg/slack-cli/build/bin" # src slack-cli
unset -f _check_and_add_path
## Android
[ -d "$HOME/Library/Android/sdk" ] && \
export ANDROID_HOME="$HOME/Library/Android/sdk"
[ -d "$HOME/Library/Android/sdk" ] && \
export ANDROID_SDK_PATH="$HOME/Library/Android/sdk"
#}}}
### machine specific .bashrc{{{
if [ -s ".$__hostname/dot.bashrc.bash" ] ; then
source ".$__hostname/dot.bashrc.bash"
fi
#}}}
### ssh-agent{{{
if [ "$__hostname" = 'quark' ] ; then
# Refs: http://qiita.com/isaoshimizu/items/84ac5a0b1d42b9d355cf
# eval `ssh-agent`
SSH_IDENTIFY_FILE="$HOME/.ssh/hisakazu_quark"
[ -z "`ssh-add -l | grep $SSH_IDENTIFY_FILE`" ] && \
ssh-add $SSH_IDENTIFY_FILE
SSH_IDENTIFY_FILE="$HOME/.ssh/hisakazu_quark_bitbucket"
[ -z "`ssh-add -l | grep $SSH_IDENTIFY_FILE`" ] && \
ssh-add $SSH_IDENTIFY_FILE
fi
if [ "$__uname" != 'Darwin' ] ; then
SSH_AGENT_FILE="${HOME}/.ssh/.ssh-agent.$__hostname"
if [ -f ${SSH_AGENT_FILE} ]; then
eval `cat ${SSH_AGENT_FILE}`
ssh_agent_exist=0
for id in `ps ax|grep 'ssh-agent'|sed -e 's/\([0-9]\+\).*/\1/'`
do
if [ "${SSH_AGENT_PID}" = "${id}" ]
then
ssh_agent_exist=1
fi
done
if [ $ssh_agent_exist = 0 ]
then
rm -f ${SSH_AGENT_FILE}
ssh-agent > ${SSH_AGENT_FILE}
chmod 600 ${SSH_AGENT_FILE}
eval `cat ${SSH_AGENT_FILE}`
ssh-add ${SSH_IDENTITY_FILE}
fi
else
ssh-agent > ${SSH_AGENT_FILE}
chmod 600 ${SSH_AGENT_FILE}
eval `cat ${SSH_AGENT_FILE}`
ssh-add ${SSH_IDENTITY_FILE}
fi
alias sshkey='eval `cat ${SSH_AGENT_FILE}`'
alias sshrm='rm -f ${SSH_AGENT_FILE}'
fi
#}}}
### hub (github{{{
# Load hub
if [ -x "`which hub`" ] ; then
eval "`hub alias -s`"
fi
#}}}
### autoupdate dotfiles{{{
REMOTE_CONFIG_DIR="$HOME/.repository"
(
dotfiles_update () {
[ $IS_INTERNET_ACTIVE -ne 0 ] && return
dotfiles_dir="$REMOTE_CONFIG_DIR/github/pinkienort/dotfiles"
[ ! -d $dotfiles_dir ] && return
cd $dotfiles_dir
git_status=`git status -s`
if [ -z "$git_status" ] ; then
echo "dotfiles >> autoupdating..."
git_update () {
git_autoupdate_logfile="$dotfiles_dir/.autoupdate.log"
echo "Date: `date`" > $git_autoupdate_logfile
is_update=`git fetch`
if [ "$is_update" ] ; then
echo ">> Pull new updates." >> $git_autoupdate_logfile
git pull origin master >> $git_autoupdate_logfile 2>&1
else
echo ">> No new updates." >> $git_autoupdate_logfile
fi
}
git_update &
else
echo "dotfiles >> following files are remained..."
git status -s
fi
}
dotfiles_update
)
#}}}
### github install#{{{
__github_info () {
# args:
# github_url
# return value:
# "$user $repo"
user="${1##*:}" ; user="${user%%\/*}"
repo="${1##*\/}"; repo="${repo%%.*}"
echo "$user $repo"
}
__github_install () {
(
if [ -z "`which git`" ] ; then
return
fi
url="$1"
arr=( $(__github_info "$url") )
user_dir="$REMOTE_CONFIG_DIR/github/${arr[0]}"
repo_dir="$user_dir/${arr[1]}"
log="$REMOTE_CONFIG_DIR/.install.log"
if [ -f "$user_dir" ] ; then
return # exception
fi
if [ ! -d "$user_dir" ] ; then
echo "Make directory: $user_dir" | tee $log
mkdir -p "$user_dir"
fi
cd "$user_dir"
if [ -d "$repo_dir" ] ; then
return
fi
echo "Install $user/$repo" | tee $log
git clone $url >> $log 2>&1 &
)
}
__repo_arr=( "git@github.com:pinkienort/dotfiles.git" "git@github.com:usp-engineers-community/Open-usp-Tukubai.git" "git@github.com:huyng/bashmarks.git" )
for url in ${__repo_arr[*]}
do
__github_install "$url"
done
#}}}
### tukubai#{{{
__tukubai_inf=( $(__github_info "git@github.com:usp-engineers-community/Open-usp-Tukubai.git") )
__tukubai_dir="$HOME/work/github/${__tukubai_inf[0]}/${__tukubai_inf[1]}"
if [ -d "$__tukubai_dir" ] ; then
export PATH="$__tukubai_dir/COMMANDS:$PATH"
fi
unset -v __tukubai_info
unset -v __tukubai_dir
unset -f __github_install
unset -f __github_info
unset -v __repo_arr
#}}}
### kancolle logbook (check wheather process is running{{{
if [ "$__hostname" = 'quark' ] ; then
logbook_pid=`ps aux| grep "logbook" | grep -v "grep" | awk '{ print $2; }'`
if [ -z $logbook_pid ]; then
echo "Kancolle Logbook is not started..."
else
echo "Kancolle Logbook is already run!"
fi
fi
#}}}
### vim settings{{{
# NOTE: make executable file without dynamic link lib.
alias vim 1>/dev/null 2>&1 # reset vim alias
if [ $? -eq 0 ] ; then
unalias vim
fi
if [ "`which ldd`" ] ; then
__which_vim=`which vim`
__vim_lib_error="`ldd $__which_vim 2>&1 1>/dev/null`"
unset -v __which_vim
else
__vim_lib_error=""
fi
if [ -z "$__vim_lib_error" ] &&
[ "$__hostname" != "cad103.naist.jp" ] &&
[ "$__hostname" != "cad104.naist.jp" ] ; then
echo "vim > use package installed"
__vim_path=`which vim`
alias vim=$__vim_path
export EDITOR=$__vim_path
unset -v __vim_path
elif [ -x /usr/bin/vim ] ; then
echo "vim > use system"
alias vim=/usr/bin/vim
export EDITOR=/usr/bin/vim
else
echo "vim > there are no vim to execute..."
export EDITOR=vi
fi
# thinca/vim-themis: test tool for vim plugins
[ -d $HOME/.vim/bundle/repos/github.com/thinca/vim-themis/bin ] &&
export PATH=$HOME/.vim/bundle/repos/github.com/thinca/vim-themis/bin:$PATH
unset -v __vim_lib_error
#}}}
### bashmarks{{{
if [ -r $HOME/.local/bin/bashmarks.sh ] ; then
. $HOME/.local/bin/bashmarks.sh
fi
#}}}
### docker{{{
# if [ -x "`which docker-machin`" ] ; then
# eval `docker-machine env default`
# fi
#}}}
### cad tools{{{
# vdec (synopsys, cadence{{{
case "$__hostname" in
"cad110.naist.jp" )
if [ `uname` = Linux ] && [ -s /opt/xilinx/ise101/ISE/settings64.sh ] ; then
echo "=========================================="
echo "======== ISE101/GP8M is available ========"
echo "=========================================="
source /opt/xilinx/ise101/ISE/settings64.sh
fi
;;
"cad101.naist.jp" | "cad102.naist.jp" )
if [ `uname` = Linux ] && [ -s /opt/xilinx/ise123/settings64.sh ] ; then
echo "=========================================="
echo "======== ISE123/GP5V is available ========"
echo "=========================================="
source /opt/xilinx/ise123/settings64.sh
fi
;;
"arch16.naist.jp" | "arch17.naist.jp" )
if [ `uname` = Linux ] && [ -s /opt/xilinx/ise134/settings64.sh ] ; then
echo "=========================================="
echo "======== ISE134/GP6V is available ========"
echo "=========================================="
source /opt/xilinx/ise134/settings64.sh
fi
;;
"cad111.naist.jp" | "cad112.naist.jp" | "cad113.naist.jp" | "cad114.naist.jp" )
if [ `uname` = Linux ] && [ -s /opt/vdec/setup/vdec_tools.2016.sh ] ; then
echo "=========================================="
echo "======== VDEC Tools are available ========"
echo "=========================================="
source /opt/vdec/setup/vdec_tools.2016.sh
fi
;;
esac
#}}}
# vivado{{{
case "$__hostname" in
"arch09.naist.jp" | "cad101.naist.jp" | "cad102.naist.jp" | \
"cad103.naist.jp" | "cad104.naist.jp" | "cad115.naist.jp" | \
"cad116.naist.jp" | "cad117.naist.jp" | "cad118.naist.jp" )
if [ `uname` = Linux ] && [ -s /opt/xilinx/Vivado/2016.2/settings64.sh ] ; then
source /opt/xilinx/Vivado/2016.2/settings64.sh
echo "=========================================="
echo "======== Vivado/ZYNQ is available ========"
echo "=========================================="
echo "Vivado: $XILINX_VIVADO"
fi
;;
esac
#}}}
# petalinux{{{
# case "$__hostname" in
# "cad101.naist.jp" | "cad102.naist.jp" | "cad106.naist.jp" | "cad107.naist.jp" )
# if [ `uname` = Linux ] && [ -s /opt/xilinx/PetaLinux/petalinux-v2016.4-final/settings.sh ] ; then
# source /opt/xilinx/PetaLinux/petalinux-v2016.4-final/settings.sh
# echo "========================================"
# echo "======== Petalinux is available ========"
# echo "========================================"
# fi
# ;;
# esac
#}}}
#}}}
### nvm (Node Version Manager{{{
if [ -d $HOME/.nvm ] ; then
export NVM_DIR="$HOME/.nvm"
fi
# This loads nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
# This loads nvm bash_completion
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
# Use latest node
if [ -x "`which nvm`" ] ; then
nvm use default
fi
#}}}
### java{{{
[ -x "/usr/libexec/java_home" ] && \
export JAVA_HOME="`/usr/libexec/java_home`"
[ -x "/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_home" ] && \
export JAVA_HOME="$(/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_home -v '1.8')"
#}}}
### pyenv{{{
#
# NOTE: pyenv is PYthon ENVironment manager...maybe.
# pyenv can install official python distributions, and also
# can install 'anaconda distributions.
# In anaconda distribution, virtual environments are created by
# 'conda' command(Usually, in officail python distributions,
# you should use 'pyenv virtualenv' command.
#
# How to manage python environments on Anaconda python distribution.
# reference: http://qiita.com/y__sama/items/5b62d31cb7e6ed50f02c
# : http://qiita.com/y__sama/items/f732bb7bec2bff355b69
# - Create new env.
# >> conda -n <env name>
# - Enable a env. DO NOT USE 'source activate/diactivate' commands
# which are introduced in official. Above commands are conflicts
# with 'source' command of 'bash'.
# >> pyenv activate <env name>
# Disable a env.
# >> pyenv deactivate <env name>
# - Install python of anaconda distribution
# >> pyenv installpython ver. or distribution>
# - Show env list.
# >> conda env list
# - Remove a env.
# >> conda remove -n <env name> --all
#
if \
# NOTE: #2 has chainer, version 2.0.0
# But current program of train_imagenet is worked
# in version 1.23.0. And #3 is has 1.23.0
#
# Date: 2017/09/21
# cad11{5,8,9} machies are assigned as machine for Machine Learning.
# Previously, cad10{3,4,5,6} are assigned, but GPUs on these machine are
# migrated to cad11{5,8}. Old pythnon env. are reamined such as
# ~/.pyenv/s{2,3,4,5,6}. Currently, no-GPU machines use same python env.,
# such as 's1'. Other machiens which has GPUs, has own env which is named
# with `hostname`.
[ "$__hostname" = "cad101.naist.jp" ] ||
[ "$__hostname" = "cad102.naist.jp" ] ||
[ "$__hostname" = "cad103.naist.jp" ] ||
[ "$__hostname" = "cad104.naist.jp" ] ||
[ "$__hostname" = "cad105.naist.jp" ] ||
[ "$__hostname" = "cad106.naist.jp" ] ||
[ "$__hostname" = "cad110.naist.jp" ] ||
[ "$__hostname" = "cad111.naist.jp" ] ||
[ "$__hostname" = "cad112.naist.jp" ] ||
[ "$__hostname" = "cad113.naist.jp" ] ||
[ "$__hostname" = "cad114.naist.jp" ] ||
[ "$__hostname" = "cad116.naist.jp" ] ||
[ "$__hostname" = "cad117.naist.jp" ] ; then
export PYENV_ROOT=$HOME/.pyenv/s1
elif \
[ "$__hostname" = "cad115.naist.jp" ] ; then
export PYENV_ROOT=$HOME/.pyenv/cad115
elif \
[ "$__hostname" = "cad118.naist.jp" ] ; then
export PYENV_ROOT=$HOME/.pyenv/cad118
elif \
[ "$__hostname" = "cad119.naist.jp" ] ; then
export PYENV_ROOT=$HOME/.pyenv/cad119
else
export PYENV_ROOT=$HOME/.pyenv
fi
if [ -d "$PYENV_ROOT" ] ; then
echo "PYENV_ROOT: $PYENV_ROOT"
export PATH=$PYENV_ROOT/bin:$PATH
eval "`pyenv init -`"
eval "`pyenv virtualenv-init -`"
fi
#}}}
### Python {{{
[ -d "$HOME/work/edge-iot/exp/chainer/dataset/imagenet/lib" ] &&
export PYTHONPATH="$HOME/work/edge-iot/exp/chainer/dataset/imagenet/lib"
#}}}
### cuda{{{
if [ -d /usr/local/cuda-8.0 ] ; then
__cuda_dir='/usr/local/cuda-8.0'
elif [ -d /usr/local/cuda-7.5 ] ; then
__cuda_dir='/usr/local/cuda-7.5'
elif [ -d /usr/local/cuda-7.0 ] ; then
__cuda_dir='/usr/local/cuda-7.0'
elif [ -d /usr/local/cuda ] ; then
__cuda_dir='/usr/local/cuda'
fi
if [ -d "$__cuda_dir" ] ; then
export CUDA_PATH="$__cuda_dir"
export PATH="$CUDA_PATH/bin:$PATH"
export CFLAGS="-I$CUDA_PATH/include"
export LDFLAGS="-L$CUDA_PATH/lib64"
export LD_LIBRARY_PATH="$CUDA_PATH/lib64:$LD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="$CUDA_PATH/lib64:$DYLD_LIBRARY_PATH"
nvcc -V
if [ -f $CUDA_PATH/include/cudnn.h ] ; then
echo ">> cudnn is available"
fi
fi
unset -v __cuda_dir
### NCCL#{{{
if [ -d "$HOME/.usr/local/cad115/nccl" ] ; then
export NCCL_ROOT=$HOME/.usr/local/cad115/nccl
fi
if [ -d "$HOME/.usr/local/cad118/nccl" ] ; then
export NCCL_ROOT=$HOME/.usr/local/cad118/nccl
fi
# On cad119, use system-wide NCCL lib.
# if [ -d "$HOME/.usr/local/cad115/nccl" ] ; then
# export NCCL_ROOT=$HOME/.usr/local/cad119/nccl
# if
if [ -n "$NCCL_ROOT" ] ; then
export CPATH=$NCCL_ROOT/include:$CPATH
export LD_LIBRARY_PATH=$NCCL_ROOT/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$NCCL_ROOT/lib:$LIBRARY_PATH
fi
#}}}
#}}}
### perl {{{
# TODO: fix error (see log
# if [ ! $IS_INTERNET_ACTIVE ] ; then
# PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib
# eval "`perl -I$HOME/perl5/lib/perl5 -Mlocal::lib`"
# fi
[ -d $HOME/.usr/local/perl/modules/lib/perl5 ] && \
export PERL5LIB=$HOME/.usr/local/perl/modules/lib/perl5
[ -d $HOME/.usr/local/perl/modules/lib64/perl5 ] && \
export PERL5LIB=$HOME/.usr/local/perl/modules/lib64/perl5:$PERL5LIB
alias iperl="perl -de 0"
#}}}
### emax{{{
# [ -d $HOME/work/emaxv/nakashim/proj-arm64.cent ] && \
# export EMAXV_SIML_PROJ_ROOT="$HOME/work/emaxv/nakashim/proj-arm64.cent"
# [ -d $EMAXV_SIML_PROJ_ROOT/bin ] && \
# export PATH=$EMAXV_SIML_PROJ_ROOT/bin:$PATH
# [ -d $EMAXV_SIML_PROJ_ROOT/lib ] && \
# export LD_LIBRARY_PATH=$EMAXV_SIML_PROJ_ROOT/lib:$LD_LIBRARY_PATH
# [ -d "$HOME/works/nakashim/proj-arm64.cent/lib/asim64-lib" ] && \
# export LD_LIBRARY_PATH="$HOME/works/nakashim/proj-arm64.cent/lib/asim64-lib:$LD_LIBRARY_PATH"
#}}}
### Rails(ruby){{{
# completion
if [ -x "`which brew`" ] &&
[ -s "`brew --prefix`/etc/bash_completion.d/rails.bash" ] ; then
. `brew --prefix`/etc/bash_completion.d/rails.bash
fi
#}}}
### go lang{{{
# macOS
[ -d /usr/local/opt/go/libexec ] && \
export GOROOT=/usr/local/opt/go/libexec # go lang bin dir
# linux
[ -d $HOME/.go/versions/1.6 ] && \
export GOROOT=$HOME/.golang/versions/1.6
export GOPATH=$HOME/.golang # workspace dir
[ ! -d "$GOPATH" ] && mkdir -p $GOPATH
[ -d "$GOPATH" ] && export PATH=$GOPATH/bin:$PATH
(
# Install twitter client written with go-lang. The process launched as child
# of this bash process so that it takes a time.
if [ ! -x "$GOPATH/bin/ringot" ] && [ -n "`which go`" ] ; then
logfile="$GOPATH/.install.log"
echo ">> install ringot... | logfile: $logfile"
go get github.com/tSU-RooT/ringot 1> $logfile 2>&1 &
go install github.com/tSU-RooT/ringot 1> $logfile 2>&1 &
fi
)
#}}}
### Rust{{{
[ -f $HOME/.cargo/env ] && . $HOME/.cargo/env
#}}}
### remove duplicate ENVs{{{
{
__remove_duplicate() {
local _env=""
local _env_name="$1"
local _ENV="${!1}"
for _e in `echo $_ENV | tr ':' ' '`; do
case ":${_env}:" in
*:"${_e}":* )
;;
* )
if [ "$_env" ]; then
_env="$_env:$_e"
else
_env=$_e
fi
;;
esac
done
eval "export $_env_name=$_env"
unset _e
unset _env
unset _env_name
unset _ENV
}
__remove_duplicate "PATH"
__remove_duplicate "LD_LIBRARY_PATH"
__remove_duplicate "DYLD_LIBRARY_PATH"
__remove_duplicate "LIBRARY_PATH"
__remove_duplicate "CPATH"
unset -f __remove_duplicate
}
#}}}
### homebrew{{{
if [ -x "`which brew`" ] ; then
if [ -s "`brew --prefix`/etc/bash_completion" ] ; then
. `brew --prefix`/etc/bash_completion
fi
if [ -d $PYENV_ROOT ] ; then
alias brew="env PATH=${PATH/${PYENV_ROOT}\/shims:/} brew"
fi
fi
#}}}
### git{{{
if [ -f "/usr/local/etc/bash_completion.d/git-completion.bash" ] ; then
# git-completion
. "/usr/local/etc/bash_completion.d/git-completion.bash"
fi
if [ -f "/usr/local/opt/bash-git-prompt/share/gitprompt.sh" ]; then
# git-prompt
__GIT_PROMPT_DIR="/usr/local/opt/bash-git-prompt/share"
. "/usr/local/opt/bash-git-prompt/share/gitprompt.sh"
fi
#}}}
if [ -f $HOME/.env.dmm.sh ] ; then
. $HOME/.env.dmm.sh
fi
# these commands must be last of file.
unset -v __uname
unset -v __hostname
update_date
update_time
function jira_ticket_url() {
if [ -z "$1" ] ; then
echo "Error: need ticket number." 1>&2
return 1
fi
echo "https://jira.arms.dmm.com/browse/"$1
return 0
}
if [ -x "$(which direnv)" ] ; then
eval "$(direnv hook bash)"
fi
if [ -f "/usr/local/opt/bash-git-prompt/share/gitprompt.sh" ]; then
GIT_PROMPT_ONLY_IN_REPO=1
export GIT_PROMPT_END_USER='\n\[\033[0;37m\]($(_print_battery_status)) $(date +%H:%M)\[\033[0;0m\] $ '
__GIT_PROMPT_DIR="/usr/local/opt/bash-git-prompt/share"
source "/usr/local/opt/bash-git-prompt/share/gitprompt.sh"
fi
# bash completion
if [ -f "/usr/local/etc/bash_completion" ] ; then
. "/usr/local/etc/bash_completion"
fi
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
eval "$(direnv hook bash)"
if [ -x "`which toot`" ] ; then
tt () { toot post "$@"; }
fi