-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
1796 lines (1508 loc) · 59.5 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
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
# -*- mode: shell-script;coding:utf-8 -*-
# .bashrc
# Note: no interactive stuff here, ~/.bashrc is loaded by all scripts thru ~/.profile!
# set -x
if [ -n "${EMACS_BASH_COMPLETE:-}" ] ; then
return
fi
set +o posix # not POSIX: allow function-names-with-dashes
### TODO: /home/pjb/.bashrc: line 92: INSIDE_EMACS: unbound variable
# Source global definitions
#[ -f /etc/bashrc ] && . /etc/bashrc
function bashrc_set_mask(){
if ((UID==0)) ; then
umask 022 # rwxr-xr-x
else
umask 022 # rwxr-xr-x And we'll set the access rights of the directories...
fi
}
function bashrc_set_host_uname(){
uname="$(uname -s)"
if [ -r ~/.config/host ] ; then
hostname=$(cat ~/.config/host)
else
hostname=$(hostname -f)
fi
}
function bashrc_set_DISPLAY(){
# case "$DISPLAY" in
# /tmp/launch-*/org.x:0) export DISPLAY=:0.0 ;;
# esac
export DISPLAY=${DISPLAY:-:0.0}
}
function bashrc_clean_XDG_DATA_DIRS(){
# Remove prefix or suffix :* and duplicate ::* -> :
XDG_DATA_DIRS="$(echo "$XDG_DATA_DIRS"|sed -e 's/^:\+//' -e 's/:\+$//' -e 's/:\+/:/g')"
}
function bashrc_set_prompt(){
# Thanks Twitter @climagic for the # prefix advice.
#
# COLOR_PROMPT, INSIDE_EMACS, etc, are not transmitted in
# chroots, and other subprocesses where the environment is
# reset. Therefore we reset use_color from the terminal below.
#
local use_color="${COLOR_PROMPT:-false}"
local escape=''
local bold="${escape}"'[1m'
local underline="${escape}"'[4m'
local blink="${escape}"'[5m'
local invert="${escape}"'[7m'
local no_bold="${escape}"'[22m'
local no_underline="${escape}"'[24m'
local no_blink="${escape}"'[25m'
local no_invert="${escape}"'[27m'
local black="${escape}"'[30m'
local red="${escape}"'[31m'
local green="${escape}"'[32m'
local yellow="${escape}"'[33m'
local blue="${escape}"'[34m'
local magenta="${escape}"'[35m'
local cyan="${escape}"'[36m'
local white="${escape}"'[37m'
local black_back="${escape}"'[40m'
local red_back="${escape}"'[41m'
local green_back="${escape}"'[42m'
local yellow_back="${escape}"'[43m'
local blue_back="${escape}"'[44m'
local magenta_back="${escape}"'[45m'
local cyan_back="${escape}"'[46m'
local white_back="${escape}"'[47m'
local normal="${escape}"'[0m'
# ---
local chroot=''
local prefix=''
local cookie=''
local ibam=''
# shellcheck disable=SC2016
local display='$(case "$DISPLAY" in (*/*) basename "$DISPLAY" ;; (*) echo "$DISPLAY" ;; esac)'
local available='$(/bin/df -h .|awk '\''/dev/{print $4}'\'')'
local time='$(date +%H:%M)'
local base='[\u@\h '"${display}"' \W '"${available}"']'
local prompt='$ '
if ((UID==0)) ; then
prompt='# '
fi
if [ -n "${INSIDE_EMACS:-}" ] ; then
TERM=emacs
fi
case "$TERM" in
(dumb)
# -n = non-zero string
if [ -n "${INSIDE_EMACS:-}" -o -n "${SCHROOT_CHROOT_NAME:-}" ] ; then
prefix="\\w"
use_color=true
fi
;;
(emacs)
prefix="\\w"
use_color=true
;;
(xterm)
use_color=true
;;
esac
export COLOR_PROMPT="${use_color}"
use_color=false
if type -path period-cookie >/dev/null 2>&1 ; then
# shellcheck disable=SC2016
cookie='$('"$(type -path period-cookie)"')'
fi
if type -p ibam >/dev/null 2>&1 ; then
ibam="\$(ibam|head -1|sed -e 's/Charge time left: */C\//' -e 's/Battery time left: */B\//' -e 's/Total battery time: */F\//')"
fi
if [ -n "${SCHROOT_CHROOT_NAME:=}" ] ; then
chroot="${SCHROOT_CHROOT_NAME:=}"
fi
if [ -n "$chroot" ] ; then
chroot="(${chroot})"
fi
if $use_color ; then
if [ -n "$chroot" ] ; then
chroot="\[${red_back}${black}\]${chroot}\[${normal}\]"
fi
# if [ -n "$cookie" ] ; then
# cookie="\[${black_back}${cyan}\]${cookie}\[${normal}\]"
# fi
if [ -n "$prefix" ] ; then
prefix="\[${yellow}\]${prefix}\[${normal}\]"
fi
if [ -n "$ibam" ] ; then
ibam="\[${black}${yellow_back}\]${ibam}\[${normal}\]"
fi
if [ -n "$time" ] ; then
time="\[${yellow}${black_back}\]${time}\[${normal}\]"
fi
if [ -n "$base" ] ; then
base="\[${cyan}${black_back}\]${base}\[${normal}\]"
fi
if [ -n "$prompt" ] ; then
prompt="\[${red}${black_back}\]${prompt}\[${normal}\]"
fi
fi
if [ -n "$prefix" ] ; then
prefix="\n${prefix}\n"
fi
export PS1="${chroot}${cookie}${prefix}${ibam}${time}${base}${prompt}"
export SAVED_PS1="$PS1"
#PS1='$(echo "${BLUE} 3.8.15.16.32-2.8 ${CYAN} 1.8.32.41.49-5 ${NORMAL}")'"$SAVED_PS1"
#PS1="$(echo "${BLUE} 3.8.15.16.32-2.8 ${CYAN} ${NORMAL}")$SAVED_PS1"
}
function bashrc_set_ulimit(){
case "${uname}" in
Darwin)
ulimit -s 32768
stty erase >/dev/null 2>&1
defaults write org.macosxforge.xquartz.X11 enable_test_extensions -boolean true
;;
*)
case $(uname -o) in
Cygwin)
true
;;
*)
ulimit -s 32768
;;
esac
esac
ulimit -c unlimited
}
################################################################################
###
### Utility
###
function quote(){
# concatenate all the arguments and shell-quote them.
printf '%s\n' "$*" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"
# printf '%s\n' "$*" | sed -e 's,\([^-+=:/_,.~^A-Za-z0-9]\),\\\1,g'
}
function quoteRegexp(){
# concatenate all the arguments and regexp-quote them.
printf '%s\n' "$*" | sed 's/\(.\)/[\1]/g'
}
################################################################################
###
### List processing
###
function member(){
local item="$1" ; shift
for arg ; do
if [ "$item" = "$arg" ] ; then
echo T
return 0
fi
done
echo NIL
return 1
}
function reverse(){
local args=("$@")
i=${#args[@]}
while [ "$i" -ge 0 ] ; do
echo "${args[$i]}"
i=$(( i - 1 ))
done
}
function remove(){
local element="$1" ; shift
for arg ; do
if [ "$element" != "$arg" ] ; then
echo "$arg "
fi
done
}
function joinWithSeparator(){
local separator="$1" ; shift
local sep=''
for arg ; do
echo -n "${sep}${arg}"
sep="$separator"
done
echo ''
}
function appendToListVariable(){
# appendToList VARIABLE element...
# Appends to the array VARIABLE each element.
# Example: a=(1 2 3) ; appendToList a 4 5 6 ; echo ${a[@]} --> 1 2 3 4 5 6
local var=$1 ; shift
eval "${var}+=(\"\${@}\")"
}
function appendNewToStringVariableDirectoryIfExists(){
# appendNewToStringVariableDirectoryIfExists VARIABLE dir...
# Appends to the VARIABLE each directory, if it exists as a directory [ -d dir ].
local var=$1 ; shift
ps=( $(eval "if [ -z \"\$${var}\" ] ; then true ; else echo \"\$${var}\"|tr ':' '\012' ; fi") )
for dir ; do
if [ -d "${dir}/." -a "$(member "${dir}" "${ps[@]}")" = NIL ] ; then
eval "if [ -z \"\$${var}\" ] ; then ${var}=\"${dir}\" ; else ${var}=\"\$${var}:${dir}\" ; fi"
fi
done
}
function prependNewToStringVariableDirectoryIfExists(){
# prependNewToStringVariableDirectoryIfExists VARIABLE dir...
# Prepend to the VARIABLE each directory, if it exists as a directory [ -d dir ].
# The last processed will be before in the resulting list.
local var=$1 ; shift
ps=( $(eval "if [ -z \"\$${var}\" ] ; then true ; else echo \"\$${var}\"|tr ':' '\012' ; fi") )
for dir in "$@" ; do
if [ -d "${dir}/." -a "$(member "${dir}" "${ps[@]}")" = NIL ] ; then
eval "if [ -z \"\$${var}\" ] ; then ${var}=\"${dir}\" ; else ${var}=\"${dir}:\$${var}\" ; fi"
fi
done
}
function prependIfDirectoryExists(){
local dir
local result=()
for dir in $(reverse "$@") ; do
if [ NIL != "$(member "$dir" ${result[@]})" ] ; then
result=("$dir" $(remove "$dir" ${result[@]}))
elif [ -d "$dir" ] ; then
result=("$dir" ${result[@]})
fi
done
printf '%s\n' "${result[@]}"
}
################################################################################
###
### Generation of bash_env
###
de="$HOME/.bash_env-default" # default .bash_env, when the hostname is not found.
he="$HOME/.bash_env-host-$(hostname)" # where the environment variables are actually stored.
be="$HOME/.bash_env-$$" # temporary file for new environment variables
function first_locale(){
local locale
for locale in "$@" ; do
if locale -a 2>/dev/null | grep -q -s "^${locale}\$" ; then
break
fi
done
echo $locale
}
function be_comment(){
printf "# %s\n" "$@" >> "$be"
}
function be_variable(){
local name="$1"
local value="$2"
printf "%s=%s\nexport %s\n" "$name" "$(quote "$value")" "$name" >> "$be"
}
function be_unset(){
local name="$1"
printf "unset %s\n" "$name" >> "$be"
}
function be_terminate(){
mv "$be" "$he"
cp "$he" "$de"
}
function be_append_terminate(){
# append the added environment to the host environment.
cat "$be" >> "$he" && rm "$be"
}
function be_generate(){
local bindirs
local mandirs
local sharedirs
local lddirs
local editors
local list
local value
local distrib="$("$HOME/bin/distribution" -i)"
local opt="$HOME/opt/${distrib}"
if [ -d "${opt}/gems" ] ; then
be_variable GEM_HOME "${opt}/gems"
fi
# (prependIfDirectoryExist (reverse (bindings))) ==> searched in order.
bindirs=(
# "$HOME/esp/xtensa-esp32-elf/bin"
# "$HOME/Library/Python/3.10/bin"
# "$HOME/anaconda3/bin"
# "/opt/anaconda3/bin"
# # Fucking idiotic pyenv, it can't find it's own stuff!!!
# "$HOME/.pyenv/bin"
# "$HOME/.pyenv/libexec"
# "$HOME/.pyenv/plugins/python-build/bin"
# Same for the idiot fucker rbenv, it can't find it's own stuff either!!!
"$HOME/.rbenv/bin"
"$HOME/.rbenv/libexec"
"/usr/lib/rbenv/bin"
"/usr/lib/rbenv/libexec"
"$HOME/.rvm/bin" # Add RVM to PATH for scripting
"${GEM_HOME}/bin" # Local Ruby Gems
"$HOME/bin"
"$HOME/.local/bin"
"$opt/lib/nodejs/node-v16.16.0-linux-x64/bin"
"$opt/bin"
# #/data/languages/acl82express/bin
# /data/languages/bigloo4.1a/bin
# /data/languages/ccl/bin
# #/data/languages/clisp/bin
# /data/languages/cmucl/bin
# /data/languages/ecl/bin
# #/data/languages/gcl-2.6.7/bin
# #/data/languages/sbcl/bin
/opt/haskell-language-server/bin
/opt/local/lib/postgresql84/bin # on galatea
/opt/local/lib/postgresql10/bin # on larissa
/opt/local/libexec/gnubin
/opt/local/sbin
/opt/local/bin
/opt/local/libexec/rbenv
# /opt/*/bin
/opt/X11/bin
/opt/sbin
/opt/bin
/usr/local/opt/coreutils/libexec/gnubin
/usr/local/opt/findutils/libexec/gnubin
/usr/local/sbin
/usr/local/bin
/usr/X11R6/bin
/usr/X11/bin
/usr/games
/usr/sbin
/usr/bin
/sbin
/bin
)
sharedirs=(
"$opt/*/share"
"$opt/share"
/opt/*/share
)
mandirs=(
"$opt/*/share/man"
"$opt/share/man"
/opt/*/share/man
/opt/*/man
/opt/local/share/man
/opt/local/man
/usr/X11R6/man
/usr/X11/man
/usr/local/share/man
/usr/share/man
/usr/man
)
lddirs=(
"$opt/*/lib"
"$opt/lib"
/opt/*/lib
/opt/local/lib
/usr/local/lib64
/usr/local/lib
/usr/X11R6/lib
/usr/X11/lib
/usr/lib
/lib
)
editors=(
"$HOME/bin/ec"
emacsclient
ed
vi
)
be_comment '-*- mode:shell-script;coding:iso-8859-1 -*-'
be_comment '.bash_env'
be_comment 'Non interactive shells'
be_comment '########################################################################'
be_comment ''
be_comment 'Unfortunately, we must be careful not launching subshells from'
be_comment '.bash_env, since it is loaded by subshells; that gives infinite'
be_comment 'recursions). '
be_comment ''
be_comment 'So we will have only constant variable definitions here, and this'
be_comment 'file will be generated from ~/.bashrc from time to time...'
be_comment ''
be_variable PATH "$(joinWithSeparator \: $(prependIfDirectoryExists ${bindirs[@]} ${PATH//:/ }))"
# WARNING: CDPATH is quite a strong setting!
# PROMPT_COMMAND='export CDPATH="$(pwd -L)"'
be_variable INPUTRC "$HOME/.inputrc"
be_unset LS_COLORS
be_variable USERNAME "$USER"
be_comment 'My compilation environment:'
be_variable COMMON "$HOME/src/public/common"
be_variable MAKEDIR "$COMMON/makedir"
be_variable COMPILATION_TARGET "$(uname)"
local e
case "${uname}" in
Darwin)
if [ 1 = "$(mfod -l|wc -l)" ] ; then
mfod -s 1
fi
# socket=(--socket-name=/tmp/emacs${UID}/server)
# EDITOR, VISUAL, etc, take only the command, no arguments.
e="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"
e=$HOME/bin/ec
be_variable EDITOR "$e"
be_variable VISUAL "$e"
be_variable CVSEDITOR "$e"
;;
*)
for e in "${editors[@]}" ; do
if [ -x "$e" ] ; then
be_variable EDITOR "$e"
be_variable VISUAL "$e"
be_variable CVSEDITOR "$e"
break
fi
done
;;
esac
# TODO: Check same thing is done elsewhere:
list="$(joinWithSeparator \: $(prependIfDirectoryExists ${sharedirs[@]}))"
if [ -s "$list" ] ; then
if [ -s "$XDG_DATA_DIRS" ] ; then
be_variable XDG_DATA_DIRS "$list:$XDG_DATA_DIRS"
else
be_variable XDG_DATA_DIRS "$list"
fi
fi
be_variable MANPATH "$(joinWithSeparator \: $(prependIfDirectoryExists ${mandirs[@]} ${MANPATH//:/ }))"
be_variable LD_LIBRARY_PATH "$(joinWithSeparator \: $(prependIfDirectoryExists ${lddirs[@]} ${LD_LIBRARY_PATH//: / }))"
if [ -d /usr/lib/x86_64-linux-gnu/pkgconfig/ ] ; then
be_variable PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
fi
be_variable LD_RUNPATH_SEARCH_PATHS /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.5/lib/darwin
be_variable DYLD_LIBRARY_PATH /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.5/lib/darwin
be_comment 'ANSI terminal codes:'
be_variable CYAN_BACK "[46m"
be_variable MAGENTA_BACK "[45m"
be_variable BLUE_BACK "[44m"
be_variable YELLOW_BACK "[43m"
be_variable GREEN_BACK "[42m"
be_variable RED_BACK "[41m"
be_variable BLACK_BACK "[40m"
be_variable WHITE_BACK "[47m"
be_variable WHITE "[37m"
be_variable CYAN "[36m"
be_variable MAGENTA "[35m"
be_variable BLUE "[34m"
be_variable YELLOW "[33m"
be_variable GREEN "[32m"
be_variable RED "[31m"
be_variable BLACK "[30m"
be_variable NO_INVERT "[27m"
be_variable NO_BLINK "[25m"
be_variable NO_UNDERLINE "[24m"
be_variable NO_BOLD "[22m"
be_variable INVERT "[7m"
be_variable BLINK "[5m"
be_variable UNDERLINE "[4m"
be_variable BOLD "[1m"
be_variable NORMAL "[0m"
be_variable GOTO_HOME ""
be_variable CLEAR_HOME ""
# be_variable GREP_OPTIONS '--color=always' # deprecated, use function.
be_variable CVSROOT ''
be_variable CVS_RSH ssh
be_variable IDF_PATH "$HOME/esp/esp-idf"
value=/usr/share/kaffe
if [[ -d $value/. ]] ; then
be_variable KAFFEHOME "$value"
list=''
appendNewToStringVariableDirectoryIfExists list \
"$JAVA_HOME"/lib/java.io.zip \
"$KAFFEHOME"/Klasses.jar \
/usr/local/share/kaffe/pizza.jar \
"$JAVA_BASE"/mSQL-JDBC_1.0b3/imaginary.zip \
"$JAVA_HOME"/lib/classes.zip \
"$JAVA_HOME"/lib/i18n.jar \
"$JAVA_HOME"/lib/rt.jar
be_variable classpath_kaffe "$list"
be_variable PATH "${JAVA_HOME}/bin:${PATH}"
fi
value=/usr/local/languages/java
if [ -d $value/. ] ; then
be_variable JAVA_BASE "$value"
be_variable JAVA_HOME "$JAVA_BASE"/jdk1.1.6/
list=''
appendNewToStringVariableDirectoryIfExists list \
"$JAVA_HOME"/lib/classes.zip \
"$JAVA_BASE"/swing-1.0.3/swingall.jar \
"$JAVA_BASE"/jaccess-1.0/jaccess.jar \
"$JAVA_BASE"/mSQL-JDBC_1.0b3/imaginary.zip
be_variable classpath_jdk "$list"
be_variable CLASSPATH "${classpath_jdk:?}"
if [ -d /usr/local/JavaApps/. ] ; then
be_variable PATH "/usr/local/JavaApps:${JAVA_HOME}/bin:${PATH}"
else
be_variable PATH "${JAVA_HOME}/bin:${PATH}"
fi
fi
be_variable JAVA_TOOL_OPTIONS '-Dfile.encoding=UTF8 -Xmx4g'
value=/opt/local/share/java/gradle
if [ -d $value/. ] ; then
be_variable GRADLE_HOME "$value"
fi
be_variable JAVA_TOOL_OPTIONS '-Dfile.encoding=UTF8 -Xmx6g'
if [ "${uname}" = Darwin ] ; then
be_variable JAVA_HOME "$(/usr/libexec/java_home)"
fi
be_comment 'Generic environment:'
be_variable TZ Europe/Paris
be_unset GNOME_KEYRING_CONTROL
# --------------------
# Locale clusterfuck
# --------------------
#
# Unset, in reverse order of priority, to avoid warnings…
# Then, check the locales first: often, the wanted locales are not available!
#
# local fr=$(first_locale fr_FR.UTF-8 C)
local en=$(first_locale en_US.UTF-8 C)
be_unset LANGUAGE # If the following are not defined.
be_unset LANG # If the following are not defined.
be_unset LC_CTYPE # If LC_ALL is not defined.
be_unset LC_COLLATE # If LC_ALL is not defined.
be_unset LC_TIME # If LC_ALL is not defined.
be_unset LC_NUMERIC # If LC_ALL is not defined.
be_unset LC_MESSAGES # If LC_ALL is not defined.
be_unset LC_MONETARY # If LC_ALL is not defined.
be_unset LC_ALL # Most prioritary.
be_variable LANG "${en}"
# if [ -d "$HOME/.pyenv" ] ; then
# be_variable PYENV_ROOT "$HOME/.pyenv"
# fi
be_variable RUBYOPT '-Eutf-8'
# be_variable RUBYLIB /usr/bin/ruby2.5
be_unset XMODIFIERS
# may be overriden by host specific bashrc.
be_variable REPLYTO 'Pascal J. Bourguignon <pjb@informatimago.com>'
be_variable MAILHOST mail.informatimago.com
case "${uname}" in
(Darwin)
be_variable MAIL "/var/mail/$USER"
;;
(*)
be_variable MAIL "/var/spool/mail/$USER" # It's the default.
;;
esac
be_variable MAILPATH "${MAIL}" # "${MAIL}:/larissa/root/var/spool/mail/$USER"
if [ -r /usr/local/share/file/magic.mgc ] ; then
be_variable MAGIC /usr/local/share/file/magic.mgc
fi
be_variable SHELL /bin/bash # Seems it's not defined in cygwin bash...
be_variable ESHELL /bin/bash
be_variable NNTPSERVER news.individual.net
be_variable IRCNICK pjb
be_variable IRCNAME 'Pascal J. Bourguignon'
be_variable IRCSERVER irc.libera.chat
be_variable BROWSER /usr/bin/lynx
be_variable LYNX_CFG "$HOME/.lynx.cfg"
be_comment 'Application environments:'
be_variable HDF5_USE_FILE_LOCKING FALSE # for nfs file accesses.
be_variable WRITE_ASF 1 # aviplay record:
if [[ -d /usr/local/apps/netscape ]] ; then
be_variable MOZILLA_HOME /usr/local/apps/netscape
fi
be_variable MINICOM '-M'
be_variable CDR_DEVICE 0,0,0
be_variable CDR_SPEED 4
be_variable CDR_FIFOSIZE 16M
be_variable ENSCRIPT ' -TA4 -fCourier10 -FCourier-Bold12 -B -h --header="" --margins=:::12 '
be_variable GENSCRIPT "$ENSCRIPT"
be_variable NENSCRIPT "$ENSCRIPT"
be_variable HTML_TIDY "$HOME/public_html/tidy.config"
be_variable ETAGS
be_variable CTAGS
be_variable GDFONTPATH /usr/share/fonts/ttf-bitstream-vera
be_variable DTK_PROGRAM espeak
be_variable COOKIE_FILES "${HOME}/ALL.cookies"
# be_variable ORACLE_BASE /home/oracle/app/oracle
# be_variable ORACLE_HOME "$ORACLE_BASE"/product/8.0.5
# be_variable ORACLE_SID orcl
# be_variable NLS_LANG fr_FR.WE8ISO8859P1
# be_variable NLS_DATE_FORMAT 'SYYYY-MM-DD HH24:MI:SS'
# be_variable LD_LIBRARY_PATH "$ORACLE_HOME"/lib:"$ORACLE_HOME"/jdbc/lib:"$LD_LIBRARY_PATH"
# be_variable PGDATABASE quotedb
be_comment 'antialiasing in QT applications'
be_variable QT_XFT 1
# ~/Qt/5.8/clang_64/bin
be_variable SHOOPSH /usr/local/share/shoop/shoop.sh
be_variable SHOOPMOD /usr/local/share/shoop/modules
be_variable SHOOPPATH "$SHOOPMOD"
if [ -d /usr/local/cint/. ] ; then
be_variable CINTSYSDIR /usr/local/cint
fi
be_variable N_PREFIX "$HOME/.local/n"
be_terminate
}
function readlink_f(){
local path="$1"
local result
result=$(readlink -f "$path" 2>/dev/null)
if [ $? -eq 0 ] ; then
echo "$result"
else
# If readlink -f is not available, we try to emulate it:
if [ -L "$path" ] ; then
local dir=$(dirname "$path")
local link=$(basename "$path")
cd "$dir"
local target=$(readlink "$link")
if [ $? -eq 0 ] ; then
readlink_f "$target"
else
echo "$path"
fi
else
echo "$path"
fi
fi
}
function bashrc_generate_bash_env(){
cat <<'EOF'
# -*- mode:shell-script;coding:iso-8859-1 -*-
# .bash_env
# Non interactive shells
# ########################################################################
#
# Unfortunately, we must be careful not launching subshells from
# .bash_env, since it is loaded by subshells; that gives infinite
# recursions).
#
# So we will have only constant variable definitions here.
# ~/.bashrc generates a ~/.bash_env-host-$(hostname) from time to time...
hostname="$(hostname)"
he="$HOME/.bash_env-host-${hostname}"
if [ -r "$he" ] ; then
source "$he"
else
source "$HOME/.bash_env-default"
fi
ee="$HOME/.bash_env-emacs-${hostname}"
[ -r "$ee" ] && source "$ee"
unset ee he hostname
EOF
}
function bashrc_generate_and_load_environment(){
# User specific environment and startup programs
local distrib="$("$HOME/bin/distribution" -i)"
# export BASH_ENV="$HOME/.bash_env-${distrib}"
export BASH_ENV="$HOME/.bash_env"
export ENV="$BASH_ENV"
if [ -f "$BASH_ENV" -a -f "$he" ] ; then
if [ "$HOME/rc/bashrc" -nt "$BASH_ENV" ] ; then
bashrc_generate_bash_env > "$BASH_ENV"
be_generate
elif [ "$HOME/rc/bashrc" -nt "$he" ] ; then
be_generate
fi
else
bashrc_generate_bash_env > "$BASH_ENV"
be_generate
fi
source "$(dirname "$(readlink_f "${BASH_SOURCE[0]}")")/bashrc-keys"
source "$BASH_ENV"
unset be he de
if type -p rbenv 2>/dev/null 1>&2 ; then
eval "$(rbenv init -)"
fi
# # /home/pbourguignon/.local/lib/python2.7/site-packages
# if type -p pyenv 2>/dev/null 1>&2 ; then
# eval "$(pyenv init -)"
# fi
}
########################################################################
function bashrc_load_completions(){
# ----------------------------------------
# Some commands in $HOME/bin/* have a bash auto-completion feature.
# ----------------------------------------
case "$BASH_VERSION" in
4.[1-9]*)
if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then
source /opt/local/etc/profile.d/bash_completion.sh
fi
;;
esac
if [ "$(uname)" != 'CYGWIN_NT-6.1-WOW64' ] ; then
local script
for script in radio fpm new-password religion ; do
if type -p "$script" 2>&1 >/dev/null ; then
eval $( "$script" --bash-completion-function )
fi
done
fi
}
function bashrc_maybe_load_shelly(){
local shelly_home="$HOME/.shelly"
if [ -s "${shelly_home}/lib/shelly/init.sh" ] ; then
source "${shelly_home}/lib/shelly/init.sh"
fi
}
function bashrc_maybe_load_gnustep(){
# ----------------------------------------
# GNUstep environment:
# ----------------------------------------
local gsr
if [ "x$GNUSTEP_MAKEFILES" = "x" ] ; then
for gsr in /usr/lib/GNUstep /usr/share/GNUstep / /GNUstep /opt/local/GNUstep/share/GNUstep/ ; do
#echo "$gsr/System/Makefiles"
if [[ -d $gsr/System/Makefiles ]] ; then
gsr=$gsr/System
break
fi
[[ -d $gsr/Makefiles ]] && break
done
[[ -f $gsr/Makefiles/GNUstep.sh ]] && source "$gsr/Makefiles/GNUstep.sh"
fi
if [ -d "$GNUSTEP_SYSTEM_ROOT" ] ; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GNUSTEP_SYSTEM_ROOT/lib"
export MANPATH="$GNUSTEP_SYSTEM_ROOT/Library/Documentation/man:${MANPATH:-/opt/local/share/man:/usr/share/man}"
fi
if [ -s "$GNUSTEP_LOCAL_ROOT" ] ; then
export MANPATH="$GNUSTEP_LOCAL_ROOT/Library/Documentation/man:${MANPATH:-/opt/local/share/man:/usr/share/man}"
fi
# alias gsgdb=/usr/local/GNUstep/System/Tools/ix86/linux-gnu/gdb
# alias dread="defaults read "
# alias dwrite="defaults write "
function wmdock (){
wmweather -s LELC -metric -kPa &
wmglobe &
wmspaceweather &
wmsun -lat 42 -lon 0 &
}
function _gopen (){
local cur app
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# shellcheck disable=SC2034
app=$(for i in $GNUSTEP_LOCAL_ROOT/Applications/*.app $GNUSTEP_SYSTEM_ROOT/Applications/*.app ; do basename "$i" ; done)
# shellcheck disable=SC2016
COMPREPLY=($(compgen -W '$app' |grep "^$cur"))
return 0
}
complete -F _gopen -o dirnames gopen
complete -f -X '!*.@(app)' openapp
}
function bashrc_maybe_load_rvm(){
# cannot set RVM without GEM .
# if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# fi
true
}
function bashrc_load_optionals(){
# Load if available:
bashrc_maybe_load_rvm
# Load if available, unless on some specific hosts:
case "${hostname}" in
*trustonic.local)
true ;;
*)
# wget_cookies=( --user-agent 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020513'
# --cookies=on --load-cookies /home/pascal/.mozilla/pascal/iolj6mzg.slt/cookies.txt )
# export wget_cookies
bashrc_maybe_load_shelly
bashrc_maybe_load_gnustep
;;
esac
}
################################################################################
###
### Interactive Commands
###
## bash specific aliases:
function variable-list(){
# vnamelist str get var that starts with str
# vnamelist (no args) get all variables
local var_name
local char
if [[ -n "${1-}" ]] ; then
for var_name in $(eval "echo \${!${1}*}"); do
echo "$var_name"
done
else
for char in _ {a..z} {A..Z} ; do
variable-list "$char"
done
fi
}
function function-list(){
typeset -f|sed -n -e 's/^\([a-zA-Z_].*\) () *$/\1/p'
}
function function-source(){
for fun ; do
declare -f "$fun"
done
}
# function function-docstring(){
# : "Returns the docstring
# of the function
# given as argument"
# local func="$1"
# local docstring
# docstring="$(declare -f "$func" | grep -A1 '^: ' | tail -n1)"
# docstring="${docstring#*: }"
# echo "$docstring"
# }
function find-in-directories(){
: "Searches the file passed as the first argument,
in each of the following directories,
and print the first match found."
local file="$1"
shift
local dir
for dir in "$@" ; do
if [[ -f "$dir/$file" ]] ; then
echo "$dir/$file"
return 0
fi
done
return 1
}
function rehash(){ hash -r ; }
alias which='type -path'