-
Notifications
You must be signed in to change notification settings - Fork 1
/
.profile
1321 lines (1233 loc) · 37.5 KB
/
.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
#
# .profile - Bourne Sh, most Ash, almost any ksh-like, some GNU Bash, etc.
#
# N.B.: GNU Bash is a big ugly slow incompatible behemoth. Do not use it if at
# all possible! Recent releases of AT&T Ksh are faster, but also big and ugly.
#
# My preference for years has been PDKsh, now as Ksh in NetBSD.
#
#ident "@(#)HOME:.profile 37.40 24/11/08 04:12:29 (woods)"
# Assumptions that may cause breakage:
#
# - the shell is more or less POSIX compatible
# - but we don't use $() for command expansion (ever!)
# - we don't use arithmetic expressions either
# - we don't use parameter expansion substring processing
# - we don't use ~ for pathname expansion (use $HOME)
# - we don't use "export VAR=value"
# - the shell supports functions (but not necessarily "typeset")
# - the shell supports "getopts" (used by some functions)
# - standard environment has been set by login(1)
# - $argv0 (if set) is `basename $0`, from .xinitrc or .xsession
# - test(1), aka "[", supports '-L' for testing symlinks
# (note that "test -L" is POSIX, but old systems had "-h")
#
# For now this all works well enough, but minimally, with Heirloom Shell; most
# modern versions of Ash, including NetBSD sh and it's bass-ackwards stunted
# clone dash; and has been tested with two of the most recent variants of Schily
# Bourne Shell (bosh and pbosh). It hasn't been tested with old SysV shells,
# old Ash, etc., in a very long time. DMD/mpx/layers support has not been
# tested in a similarly long time.
# Files referenced [all optional, some specific to the type of shell]:
#
# $HOME/.ashtype - sourced once, if 'type' command fails
# $HOME/.ashlogin - sourced once, if running ash(1) or similar (expands ~)
# $HOME/.ashrc - set as $ENV if running ash(1) or similar
# $HOME/.ashlocal - source from .ashrc, if readable
# $HOME/.bashrc - set as $ENVFILE in ~/.bashlogin
# $HOME/.bashlogin - sourced once, if running GNU bash(1)
# $HOME/.bashlogout - sourced on trap 0, if running GNU bash(1)
# $HOME/.editor - mktable'd & assigned to $EDPREF, preferred editor type
# $HOME/.kshrc - set as $ENVFILE in ~/.kshlogin
# $HOME/.kshlocal - source from .kshrc, if readable
# $HOME/.kshlogin - sourced once, if running any ksh(1)
# $HOME/.kshlogout - sourced on trap 0, if running any ksh(1)
# $HOME/.localprofile - sourced once early to set system-local prefs.
# $HOME/.mailer - name of prefered MUA command
# $HOME/.shell - mktable'd and exec'ed as shell (see end of this file)
# $HOME/.shlogin - sourced once, if running sh(1)
# $HOME/.shlogout - set on trap 0, if running sh(1) or ash(1)
# $HOME/.shrc - sourced at the beginning herein, and (again) by $ENV
# $HOME/.stty - sourced for stty command(s), etc. just before tset(1)
# $HOME/.trninit - pathname set as value for $TRNINIT
# Notes:
#
# .ashlocal, .editor, .kshlocal, .localprofile, .stty, and .shell are not
# distributed (i.e. they are expected to be specific per $HOME).
#
# .localprofile may set $PATH_IS_OKAY to "true" if it is so (and
# of course may also (re)set $PATH to make it so first.
#
# The purpose of ~/.${SHELL}login is to set up $ENV, or at least
# arrange for it to be set (e.g. as in ~/.kshlogin), and to set
# the prompt variables ($PS1, etc.) appropriately unless $ENV
# will do that when running interactively (but remember $PS1 et
# al must not be set for non-interactive shell processes!).
#
# $ENV really shouldn't ever do anything for non-interactive shells, as
# anything it does can make nightmares for portable shell scripts (both
# the writing of, and the running of them). On the other hand of course
# the utility of having non-interactive shells source $ENV does allow for
# selectively overriding built-ins that might not be fully POSIX
# compliant (e.g. to add new features).
#
# Login shells can be tested with:
#
# cd $HOME && env -i SHELL=/path/to/sh HOME=$HOME DISPLAY=$DISPLAY PATH=$PATH uxterm -ls &
#
# or (sometimes, iff the shell supports '-l' to make it a login shell):
#
# cd $HOME && env -i SHELL=/path/to/sh HOME=$HOME DISPLAY=$DISPLAY PATH=$PATH uxterm -e login -pf $USER /path/to/sh -l &
#
# Note the "cd $HOME" in the above test command. Most shell manuals say
# something like "read the .profile file in the user's home directory
# ($HOME)", or even more explicitly "read from $HOME/.profile", but in
# fact some expect to be started with their current working directory
# already in $HOME, e.g. NetBSD sh (and maybe older shells, but not dash).
#
# N.B.: $XTERM_OPTS is expected to contain '-ls', or the "*loginShell"
# X11 resource should be set, for such tests.
# ToDo:
#
# Don't force HAVE* variables if they are already set!
umask 022
echo "$0: startup PATH=$PATH" | sed 's/:/: /g' | fold -s
OPATH=$PATH
# Every shell that sources ~/.profile gets all the basic functions and variable
# settings, interactive or not!
#
# We assume ~/.profile is sourced only by login shells, and by ~/.xinitrc, and
# perhaps by a call from a (possibly remote) window manager (e.g. using
# onx11server) where the intent is to set up $PATH and other environment,
# etc. typically desired and assumed for "interactive" commands, such as
# editors, media viewers, etc.
#
# XXX probably should move all the HAVE* settings there too as they are not
# exported to the environment.... (and any other similar unexported vars)
#
FROM_DOT_PROFILE=true # tell ~/.shrc this use is effectively "interactive"
. ${HOME}/.shrc
# XXX hmmmm.... these should be in their respective ~/.*login files????
#
if ${ISATTY}; then
if is_ksh || is_bash && [ -r ${HOME}/.kshlogout ]; then
trap '. ${HOME}/.kshlogout ; exit $?' EXIT
elif [ -r ${HOME}/.shlogout ]; then
trap '. ${HOME}/.shlogout ; exit $?' 0
fi
fi
if [ "`echo ~`" = "${HOME}" -a ${RANDOM:-0} -eq ${RANDOM:-0} ]; then
#
# apparently a POSIX capable shell
#
: # OK POSIX is good -- that is all for now...
if [ -n "${KSH_VERSION}" ]; then
: # ksh93t or newer, or PDKSH.
## xxx it seems impossible to use the following without tripping up
## pdksh (which complains "ksh: : bad substitution").... but...
##elif [ -n "${.sh.version}" ]; then
## : # ksh93 or newer
fi
fi
if expr "`type ulimit 2>/dev/null`" : '^ulimit is a shell ' > /dev/null 2>&1 ; then
#
# force core, data, nofile, stack, and nproc limits to be equal to
# their maximum hard limit.
#
# (assume RLIMIT_CPU (time) and RLIMIT_FSIZE (file) are already either
# unlimited or as big as they can get)
#
# XXX sadly POSIX 1003.1 2004 only specifies '-f' (file size
# limit in 512-byte blocks, aka RLIMIT_FSIZE)
#
# ToDo N.B. first compare to "unlimited" then do "<" numerical comparison!
#
RLIMIT_CORE=`ulimit -H -c`
if [ "${RLIMIT_CORE}" != "`ulimit -S -c`" ]; then
ulimit -S -c ${RLIMIT_CORE} # coredump
fi
RLIMIT_DATA=`ulimit -H -d`
if [ "${RLIMIT_DATA}" != "`ulimit -S -d`" ]; then
# on NetBSD this will still give EINVAL....
ulimit -S -d ${RLIMIT_DATA} # data
fi
RLIMIT_STACK=`ulimit -H -s`
if [ "${RLIMIT_STACK}" != "`ulimit -S -s`" ]; then
ulimit -S -s ${RLIMIT_STACK} # stack
fi
#
# XXX AT&T KSH and GNU Bash see '-p' as pipesize (internal,
# read-only), and use '-u' for number of processes
# (RLIMIT_NPROC).
#
if is_attksh || is_bash || is_bourne_sh || is_schily_sh; then
RLIMIT_PROC=`ulimit -H -u`
if [ "${RLIMIT_PROC}" != "`ulimit -S -u`" ]; then
ulimit -S -u ${RLIMIT_PROC}
fi
else
RLIMIT_PROC=`ulimit -H -p`
if [ "${RLIMIT_PROC}" != "`ulimit -S -p`" ]; then
ulimit -S -p ${RLIMIT_PROC}
fi
fi
#
# FreeBSD, Darwin (and maybe others?) have kern.maxfilesperproc as their
# system limit for "nofile", so use that instead of an arbitrary value
# from the hard limit especially if that is "unlimited", as on Darwin
# "unlimited" causes major problems for the currently supplied version
# of Ksh-93!
#
# See: https://forums.developer.apple.com/forums/thread/722226
# and: https://github.com/ksh93/ksh/issues/591
#
SYSCTL=""
if [ -x /sbin/sysctl ]; then
SYSCTL="/sbin/sysctl"
fi
if [ -x /usr/sbin/sysctl ]; then
SYSCTL="/usr/sbin/sysctl"
fi
if [ -n "${SYSCTL}" ] && ${SYSCTL} kern.maxfilesperproc >/dev/null 2>&1; then
RLIMIT_NOFILE=`${SYSCTL} kern.maxfilesperproc | awk '{print $2}'`
else
RLIMIT_NOFILE=`ulimit -H -n`
fi
if [ "${RLIMIT_NOFILE}" != "`ulimit -S -n`" ]; then # XXX numerical comparison impossible!
ulimit -S -n ${RLIMIT_NOFILE} # nofile
if [ $? -ne 0 ]; then
new_nofile=`expr ${RLIMIT_PROC} \* 4`
echo "Unable to increase RLIMIT_NOFILE to hard limit of '$RLIMIT_NOFILE', trying $new_nofile..."
ulimit -S -n ${new_nofile}
fi
fi
else
# force nproc, data, stack, and nofiles limits to be equal to
# their maximum hard limit.
#
# (assume time, filesize, and coredump are already unlimited)
#
limit maxproc `limit -h maxproc | awk '{print $2}'`
limit datasize `limit -h datasize | awk '{print $2 * 1024}'`
limit stacksize `limit -h stacksize | awk '{print $2 * 1024}'`
limit openfiles `limit -h openfiles | awk '{print $2}'`
fi
if [ -z "${LOGNAME}" ]; then
LOGNAME=${USER}
fi
export LOGNAME
if [ -z "${UUNAME}" ]; then
if type uuname >/dev/null 2>&1; then
UUNAME=`uuname -l`
else
UUNAME=`hostname`
fi
fi
export UUNAME
if [ -z "${HOSTNAME}" ]; then
if type hostname >/dev/null 2>&1; then
HOSTNAME=`hostname`
else
HOSTNAME=${UUNAME}
fi
fi
export HOSTNAME
case "${HOSTNAME}" in
*.local)
DOMAINNAME=".local"
;;
esac
if [ -z "${DOMAINNAME}" ]; then
DOMAINNAME=`get_domainname`
fi
export DOMAINNAME
# system-local user preferences go in here
#
# n.b.: these should mostly/all be environment variables, except for settings
# which might control options herein, such as $PATH_IS_OKAY.
#
if [ -r ${HOME}/.localprofile ]; then
. ${HOME}/.localprofile
fi
if [ -n "${MANPATH}" ]; then
OMANPATH=${MANPATH}
fi
if [ -z "${MANPATH}" ]; then
if [ -r /etc/man.conf ]; then
if man -w >/dev/null 2>&1; then
# for OpenBSD et al, etc.
MANPATH=`man -w`
# and for Planix NetBSD, also expand any curly braces
# then convert the spaces to colons
MANPATH=`echo $MANPATH | sed 's/ /:/g'`
else
MANPATH=`man -w sh | sed 1q`
# drop the filename
MANPATH=${MANPATH%/*}
# drop the section subdir
MANPATH=${MANPATH%/*}
fi
elif [ -d /usr/share/man ]; then
MANPATH="/usr/share/man"
else
MANPATH="/usr/man"
fi
fi
export MANPATH
if [ -n "${INFOPATH}" ]; then
OINFOPATH=${INFOPATH}
fi
if [ -z "${INFOPATH}" ]; then
if [ -d /usr/share/info ]; then
INFOPATH="/usr/share/info"
else
INFOPATH="/usr/man"
fi
fi
export INFOPATH
if "${PATH_IS_OKAY:-false}" ; then
: # we trust $PATH has been initialized correctly on these machines....
echo "$0: keeping PATH"
else
# otherwise start fresh...
OPATH=${PATH}
# XXX on FreeBSD systems using their half-assed virtual
# environment system based on their jail(2) system call, /bin
# (and /usr/bin) will potentially be a symlink pointing to
# some shared storage, eg. /basejail/bin (and
# /basejail/usr/bin). However since it's difficult to
# portably detect the target of a symlink (there is a
# "readlink" utility on FreeBSD and newer NetBSDs, a variant
# of the older NetBSD stat(1) command), we'll just depend on
# use of $PATH_IS_OKAY for now to work around the problem.
#
# originally this code was to avoid having /bin in $PATH if
# /bin were pointing to /usr/bin (i.e. making it redundant)
### if [ -L /bin -a `ls -l /bin | awk '{print $(NF)}'` = "/usr/bin" ]; then
if [ -L /bin ]; then
PATH="/usr/bin"
### if [ -L /usr/bin -a `ls -l /usr/bin | awk '{print $(NF)}'` = "/bin" -o ! -d "/usr/bin" ]; then
elif [ -L /usr/bin -o ! -d /usr/bin ]; then
PATH="/bin"
else
PATH="/bin:/usr/bin"
fi
dirappend PATH /usr/lbin
if [ -d /usr/share/man ]; then
dirappend MANPATH /usr/share/man
else
dirappend MANPATH /usr/man
fi
fi
export PATH
set_LOCAL_et_al
# TODO: explore more options for this.... (xmkmf?)
#
# TODO: what if there's more than one variant installed?
#
# don't worry about openwin -- it's handled in the ISSUN case below
#
if [ -z "${X11PATH}" ]; then
# for X11R? try to get the newest (highest numeric value) one first...
x11paths=`eval echo /opt/X11 /local/X11R? /local/X11 /usr/X11R? /usr/X11 /usr/X??? /usr/local/X11R? /usr/local/X11`
for x11pc in `reverse_word_order ${x11paths}`; do
if [ -d ${x11pc} -a ! -L ${x11pc} -a -d ${x11pc}/bin -a -x ${x11pc}/bin/xterm ]; then
X11PATH=${x11pc}
break;
fi
done
if [ -z "${X11PATH}" ]; then
if [ -x /usr/bin/xterm ]; then
# GNU/Linux, of course, has to be different....
X11PATH="/usr"
else
X11PATH="/NO-X11-FOUND"
fi
fi
unset x11paths x11pc
fi
export X11PATH
if [ -z "${X11BIN}" ]; then
if [ -d /usr/bin/X11 -a ! -L /usr/bin/X11 ]; then
# this is never(?) used any more....
X11BIN="/usr/bin/X11"
X11MAN="/usr/man/X11"
else
# XXX: this is a best guess -- should check!
X11BIN=${X11PATH}/bin
if [ -d ${X11PATH}/share/man ]; then
X11MAN=${X11PATH}/share/man
else
X11MAN=${X11PATH}/man
fi
fi
fi
export X11BIN
export X11MAN
# deal with startx madness of $oldbindir
if [ -L /usr/X11 -a $X11BIN != /usr/X11/bin ]; then
dirremove PATH /usr/X11/bin
fi
if [ -L /usr/X11R6 -a $X11BIN != /usr/X11R6/bin ]; then
dirremove PATH /usr/X11R6/bin
fi
if [ -L /usr/X11R7 -a $X11BIN != /usr/X11R7/bin ]; then
dirremove PATH /usr/X11R7/bin
fi
# TODO: some of these we may want fixed in even if they don't exist at
# login time...
#
# On Solaris after 5.10 the most POSIX-ish behaviour is given by:
#
# PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin
#
# Ordering of PKG, SLASHOPT, GNU, and X11BIN are of course personal prefs too....
#
dirprepend PATH /usr/xpg6/bin /usr/xpg4/bin /usr/ccs/bin
dirprepend MANPATH /usr/xpg6/man /usr/xpg4/man /usr/ccs/man
dirappend PATH ${X11BIN} ${LOCAL}/bin ${CONTRIB}/bin
dirappend MANPATH ${X11MAN} ${LOCAL}/share/man ${CONTRIB}/share/man ${LOCAL}/man ${CONTRIB}/man
dirappend PATH ${PKG}/bin ${PKG}/DWB/bin
dirappend MANPATH ${PKG}/share/man ${PKG}/man
dirappend PATH ${PKG}/heirloom-xpg4/bin ${PKG}/heirloom-ccs/bin ${PKG}/heirloom-doctools/bin ${PKG}/heirloom/bin
dirappend MANPATH ${PKG}/heirloom-xpg4/man ${PKG}/heirloom-ccs/man ${PKG}/heirloom-doctools/man ${PKG}/heirloom/man
dirappend PATH ${SLASHOPT}/bin
dirappend MANPATH ${SLASHOPT}/share/man ${SLASHOPT}/man
dirappend PATH ${GNU}/bin ${SLASHOPT}/gnu/bin
dirappend MANPATH ${GNU}/share/man ${GNU}/man
dirappend PATH /Developer/usr/bin
dirappend MANPATH /Developer/usr/share/man
# silly fuzting for older OSX...
# XXX Joyent /opt/pkg/nbase/bin things are crashing sometimes now....
#if [ -d /Developer/usr/bin ]; then
# dirprepend PATH ${PKG}/nbase/bin
#fi
# always, for bootstrapped pkgsrc???
#dirappend PATH ${PKG}/nbase/bin
dirappend PATH /usr/ucb /usr/bsd
dirappend PATH ${HI_TECH_C}/bin
dirappend PATH /usr/games ${LOCAL}/games ${SLASHOPT}/games/bin
if $ISSUN; then
PATH=`echo ${PATH} | sed 's/^\/bin://'`
if [ "`uname -r | sed 's/^\([0-9]*\).*$/\1/'`" -lt 5 ]; then
if [ "X${LOGNAME}" != "Xroot" ]; then
dirprepend PATH /usr/5bin
else
dirappend PATH /usr/5bin
fi
else
dirprepend PATH /opt/SUNWspro/bin
fi
# XXX FIXME: should use OPENWINHOME ???
# XXX FIXME: should only do this if DISPLAY set???
dirappend PATH /usr/openwin/bin /usr/openwin/demo
dirappend MANPATH /usr/openwin/share/man
fi
if [ -d ${LOCAL}/dmdlayers/bin -a "X${TERM}" = "Xdmd" ]; then
DMD=${LOCAL}/dmdlayers ; export DMD
TOOLS=${DMD}/local ; export TOOLS
dirappend PATH ${DMD}/bin ${TOOLS}/bin
dirappend MANPATH ${DMD}/man ${TOOLS}/man
fi
# make sure our home-dir is set up properly...
#
if [ ! -d ${HOME}/tmp ]; then
mkdir ${HOME}/tmp
chmod 700 ${HOME}/tmp
fi
if [ ! -d ${HOME}/Mail ]; then
mkdir ${HOME}/Mail
chmod 700 ${HOME}/Mail
fi
if [ -f ${HOME}/.xinitrc ]; then
if [ ! -x ${HOME}/.xinitrc ]; then
echo "WARNING: fixing execute bit on ~/.xinitrc!"
chmod +x ${HOME}/.xinitrc
fi
if [ ! -r ${HOME}/.xsession ]; then
mv ${HOME}/.xsession ${HOME}/SAVED.xsession
ln -s .xinitrc ${HOME}/.xsession
fi
fi
# note .emacs.elc may not yet exist
if [ ! -r ${HOME}/.emacs -a -r ${HOME}/.emacs.el ]; then
rm -f ${HOME}/.emacs
ln -s .emacs.elc ${HOME}/.emacs
fi
if [ "X${HOME}" != "X/" ]; then
if [ ! -d ${HOME}/bin ]; then
mkdir ${HOME}/bin
chmod 755 ${HOME}/bin
fi
if [ -d ${HOME}/usr/bin ]; then
echo ""
echo "$0: what's up with $HOME/usr/bin?"
echo ""
sleep 5
fi
dirprepend PATH ${HOME}/.local/bin ${HOME}/bin ${HOME}/usr/bin ${HOME}/pkg/bin
dirprepend MANPATH ${HOME}/.local/share/man ${HOME}/share/man ${HOME}/man ${HOME}/usr/share/man ${HOME}/pkg/share/man ${HOME}/pkg/man
dirprepend PATH ${HOME}/go/bin
case "${PATH}" in
*:)
echo 'NOTICE: PATH already ends in a colon.'
;;
*)
PATH=${PATH}:
;;
esac
fi
#
# *PATH should finally be set properly! Just Mh and X11 set below
#
if type mktable >/dev/null 2>&1; then
MKTABLE="mktable"
else
# a little ditty to throw away comment lines....
# TODO: could call mkline (ala smail-3) if available....
# TODO: should this remove trailing comments too? (-e '/#.*$//')
mktable ()
{
sed \
-e '/^[ ]*#/d' \
-e '/^[ ]*$/d' \
${1+"$@"}
}
fi
# This is kind of crude and not likely to work all the time, but the
# idea is that since less(1) will use setlocale() if possible, we will
# try to be smart about when we can tell it about which charset it
# should try to use.
#
# note: LC_ALL, if valid, overrides all LC_* variables, LANG is the default for
# unset LC_* variables, and LESSCHARSET is the equivalent of LC_CTYPE (just for
# "less", of course)
#
# Note also that "uxterm" will (have) set LC_CTYPE=en_US.UTF-8 IFF none of
# LC_ALL, LC_CTYPE, or LANG were set on invocation.
#
HAVELOCALE=false
if type locale >/dev/null 2>&1; then
HAVELOCALE=true
fi
if [ -z "${LC_CTYPE}" -a -z "${LC_ALL}" -a -z "${LANG}" ]; then
# note TERM here is a preset one, not a proven one as below
case "${TERM}" in
wsvt25*)
# this lets those pesky high-bit chars show through...
#
# NOTE: with older versions of less 'latin1' is the only way to
# express "ISO 8859-1", while with newer versions 'latin1' is
# merely an alias for "iso8859", so is ISO-8859-*, i.e. whatever
# extended set your terminal displays.
#
# more modern versions of less, on systems with setlocale(3)
# will use LC_CTYPE (or LANG) if set.
#
LESSCHARSET="latin1"; export LESSCHARSET
#
# We'll assume for now that the console is in vt100 emulation
# mode and loaded with an "iso" (i.e. ISO-8859-1) font.
;;
xterm*)
# Xterm will normally set the environment up for itself, i.e. so
# if it was started as "uxterm" then we're NOT in this 'if'
# block!
#
# For less, from the man page:
# If neither LESSCHARSET nor LESSCHARDEF is set, but any of the strings
# "UTF-8", "UTF8", "utf-8" or "utf8" is found in the LC_ALL, LC_CTYPE or
# LANG environment variables, then the default character set is utf-8.
#
# So for plain (ascii) xterm, we probably also want to avoid
# using LESSCHARSET too....
#
unset LESSCHARSET
;;
esac
else
# Here we should have either LC_CTYPE (and/or LC_ALL and/or LANG)....
#
# first try to set LC_CTYPE (i.e. from LC_ALL or LANG) if it is not
# set...
#
if $HAVELOCALE && [ -z "${LC_CTYPE}" ]; then
eval `locale | fgrep LC_CTYPE`
fi
#
# this likely never happens, but if it is still not set, but we appear
# to have locale(1), force it to our favourite
#
if $HAVELOCALE && [ -z "${LC_CTYPE}" ]; then
# xxx should maybe check if "locale -a" reports a matching en_CA*?
LC_CTYPE="en_CA.UTF-8"
export LC_CTYPE
fi
#
# translate LC_CTYPE=en_US* to LC_CTYPE=en_CA* for S's & G's
#
case "${LC_CTYPE}" in
en_US.*)
# xxx should maybe check if "locale -a" reports a matching en_CA*?
LC_CTYPE="en_CA."${LC_CTYPE##"en_US."}
;;
esac
export LC_CTYPE
# xxx printf(3)'s "%'d" flag (i.e. the "'") is pedantic about having a
# known locale set for at least LC_NUMERIC before it does commification!
#
# XXX XXX but this hard-coded choice may not be available everywhere,
# never mind appropriate for anyone but me... On NetBSD there's a
# locale alias called "C.UTF-8", which is currently by default an alias
# for "en_US.UTF-8". but maybe the alias is more universal?
#
# xxx on Debian GNU/Linux there is a "C.utf8", and a "en_CA.utf8", and a
# "en_US.utf8", as well as "POSIX". XXX However there is only a "UTF-8"
# character map! So, presumably "en_CA.UTF-8" will work normally.
#
LC_NUMERIC="en_CA.UTF-8"
export LC_NUMERIC
LC_MONETARY="en_CA.UTF-8" # this is the only one different from en_US
export LC_MONETARY
# XXX BTW, why is $(LANG= LC_ALL= LC_CTYPE= locale charmap)=="646" on
# NetBSD but "locale -m" does not include "646" (only "US-ASCII"!)
#
# XXX Besides, shouldn't it properly be "ISO646"????
#
# xxx on Debian GNU/Linux the result is "ANSI_X3.4-1968" (which is in
# the "locale -m" list)
fi
# I am unlikely to ever want command to display times and dates in locale form!
LC_TIME="C"
export LC_TIME
# Similarly we don't need any surprises from sorting order changes!
#
# In the event LANG is set, even to a POSIX-compatible language, such as
# LANG=en_US.UTF-8 or LANG=en_GB.UTF-8 or LANG=en_CA.UTF-8, etc., the sorting
# order used by some tools will change, e.g. the "ls" command now sorts
# filenames with uppercase and lowercase first character next to each other
# (like in a dictionary), and file globbing will also no longer use the ASCII
# order either (e.g. “echo [a-z]*” will also list any filenames starting with
# uppercase letters).
LC_COLLATE="C" # alternatively: LC_COLLATE=POSIX
export LC_COLLATE
# XXX can these ($RSH and $SSH) cause problems with other tools?
# (will be OK with at least cvs and rsync which use ${argv0}_RSH)
#
if type rsh >/dev/null 2>&1 ; then
RSH="rsh"
elif [ -x /usr/ucb/rsh ]; then # maybe /usr/ucb not in $PATH?
RSH="/usr/ucb/rsh"
else
# assuming 'ssh' exists and is the only way to run remote shells...
RSH="ssh"
fi
export RSH # used by .twmrc, .ctwmrc, as well as .xinitrc
if type ssh >/dev/null 2>&1; then
SSH="ssh"
elif type ssh2 >/dev/null 2>&1; then
SSH="ssh2"
else
# assuming 'ssh' really is available...
SSH="ssh"
fi
export SSH # used by .twmrc, .ctwmrc, as well as .xinitrc
HAVEMONTH=false
if type month >/dev/null 2>&1; then
HAVEMONTH=true
fi
MONTH="AIKO" ; export MONTH
HAVELAYERS=false
if type layers >/dev/null 2>&1; then
HAVELAYERS=true
fi
HAVEMUSH=false
MAILER=mail ; export MAILER
if [ -s ${HOME}/.mailer ]; then
# mktable just throws away comments....
MAILER=`mktable ${HOME}/.mailer`
elif type mush >/dev/null 2>&1; then
HAVEMUSH=true
MAILER="mush"
elif type Mail >/dev/null 2>&1; then
MAILER="Mail"
elif type mailx >/dev/null 2>&1; then
MAILER="mailx"
fi
case "${MAILER}" in
mh)
if [ -d ${CONTRIB}/mh ]; then
dirprepend PATH ${CONTRIB}/mh/bin
dirprepend MANPATH ${CONTRIB}/mh/man
elif [ -d ${PKG}/mh ]; then
dirprepend PATH ${CONTRIB}/mh/bin
dirprepend MANPATH ${CONTRIB}/mh/man
elif [ -d ${LOCAL}/mh ]; then
dirprepend PATH ${LOCAL}/mh/bin
dirprepend MANPATH ${LOCAL}/mh/man
elif [ -d /usr/mh ]; then
dirprepend PATH /usr/mh/bin
dirprepend MANPATH /usr/mh/man
elif [ -d ${LOCAL}/bin/mh ];then
# this is a non-std setup -- ${LOCAL}/mh/man might not exist
dirprepend PATH ${LOCAL}/bin/mh
dirprepend MANPATH ${LOCAL}/mh/man
fi
;;
nmh)
if [ -d ${CONTRIB}/nmh ]; then
dirprepend PATH ${CONTRIB}/nmh/bin
dirprepend MANPATH ${CONTRIB}/nmh/man
elif [ -d ${PKG}/nmh ]; then
dirprepend PATH ${CONTRIB}/nmh/bin
dirprepend MANPATH ${CONTRIB}/nmh/man
elif [ -d ${LOCAL}/nmh ]; then
dirprepend PATH ${LOCAL}/nmh/bin
dirprepend MANPATH ${LOCAL}/nmh/man
elif [ -d /usr/nmh ]; then
dirprepend PATH /usr/nmh/bin
dirprepend MANPATH /usr/nmh/man
elif [ -d ${LOCAL}/bin/nmh ];then
# this is a non-std setup -- ${LOCAL}/nmh/man might not exist
dirprepend PATH ${LOCAL}/bin/nmh
dirprepend MANPATH ${LOCAL}/nmh/man
fi
;;
esac
if [ -z "${MAILDIR}" ]; then
if [ -d /var/mail ]; then
MAILDIR="/var/mail"
elif [ -d /var/spool/mail ]; then
MAILDIR="/var/spool/mail"
elif [ -d /usr/mail ]; then
MAILDIR="/usr/mail"
elif [ -d /usr/spool/mail ]; then
MAILDIR="/usr/spool/mail"
fi
fi
export MAILDIR
if [ -z "${UUCPSPOOLDIR}" ]; then
if [ -d /var/spool/uucp ]; then
UUCPSP0OLDIR=/var/spool/uucp
export UUCPSPOOLDIR
elif [ -d /usr/spool/uucp ]; then
UUCPSPOOLDIR=/usr/spool/uucp
export UUCPSPOOLDIR
fi
fi
# use MAIL instead of MAILPATH, primarily to avoid the clash of using
# a POP specification in MAILPATH for emacs VM
#
unset MAILPATH
if [ -z "${MAIL}" ]; then
MAIL=${MAILDIR}/${LOGNAME}
fi
export MAIL
HAVECALENDAR=false
if type calendar >/dev/null 2>&1; then
HAVECALENDAR=true
fi
HAVEFORTUNE=false
if type fortune >/dev/null 2>&1; then
HAVEFORTUNE=true
FORTUNE=fortune ; export FORTUNE
fi
if type less >/dev/null 2>&1; then
PAGER="less"
LESS="-M" ; export LESS
if [ ! -f ${HOME}/.less ]; then
# xxx lesskey(1) seems to have gone missing on OSX 10.8 and 10.9
# (maybe even on 10.7 too?)
if type lesskey >/dev/null 2>&1; then
if [ ! -f ${HOME}/.lesskey ]; then
echo "N next-file" > ${HOME}/.lesskey
echo "P prev-file" >> ${HOME}/.lesskey
fi
lesskey
fi
fi
elif [ -x /usr/xpg4/bin/more ]; then
# SunOS-5's, at least, has the 'G' command!
PAGER="/usr/xpg4/bin/more"
# use '-s' as it can't be turned on later during runtime
MORE="-s" ; export MORE
elif type more >/dev/null 2>&1; then
PAGER="more"
# use '-s' as it can't be turned on later during runtime
MORE="-sw" ; export MORE
else
PAGER="cat"
fi
export PAGER
if [ "${PAGER}" = "less" ]; then
MANPAGER="${PAGER} -Rsi"; export MANPAGER # n.b. more and less both suppport "-Rsi"
fi
# NetBSD's new apropos is horrible, but this puts it in legacy mode
#
APROPOS="-l"
export APROPOS
if [ -s "${HOME}/.editor" ]; then
# mktable just throws away comments....
EDPREF=`mktable ${HOME}/.editor` ; export EDPREF
fi
HAVEEMACS=false
if [ -z "${MY_EMACS}" ]; then
if type emacs >/dev/null 2>&1; then
MY_EMACS=`type emacs`
MY_EMACS=`expr "${MY_EMACS}" : '^[^/]*\(/[^ )]*\)'`
case `uname -s` in
Darwin*)
# native emacs is usually very old!
if [ -x /opt/pkg/bin/emacs ]; then
MY_EMACS=/opt/pkg/bin/emacs
elif [ -x /usr/pkg/bin/emacs ]; then
MY_EMACS=/usr/pkg/bin/emacs
elif [ -x /usr/local/bin/emacs ]; then
MY_EMACS=/usr/local/bin/emacs
fi
;;
esac
export MY_EMACS
HAVEEMACS=true
fi
else
# assume $MY_EMACS exists, or will exist
HAVEEMACS=true
fi
case "${EDPREF}" in
emacs|"")
HAVEJOVE=false
if ${HAVEEMACS}; then
EDITOR="${MY_EMACS}"
elif type jove >/dev/null 2>&1; then
EDITOR="jove"
HAVEJOVE=true
else
EDITOR="ed"
fi
if ${HAVEEMACS} ; then
VISUAL="${MY_EMACS}"
elif ${HAVEJOVE} ; then
VISUAL="jove"
else
VISUAL="vi"
fi
;;
vi)
if type nvi >/dev/null 2>&1; then
EDITOR="nvi"
elif type vi >/dev/null 2>&1; then
EDITOR="vi"
else
EDITOR="ed"
fi
if type nvi >/dev/null 2>&1; then
VISUAL="nvi"
elif type vi >/dev/null 2>&1; then
VISUAL="vi"
else
VISUAL="no-visual-editor"
fi
;;
*)
if type nvi >/dev/null 2>&1; then
EDITOR="nvi"
elif type vi >/dev/null 2>&1; then
EDITOR="vi"
else
EDITOR="ed"
fi
if type ${EDPREF} >/dev/null 2>&1; then
VISUAL=${EDPREF}
else
VISUAL=${EDITOR}
fi
esac
export EDITOR
export VISUAL
EXINIT="set sm" ; export EXINIT
HAVEAUPLAY=false
if type auplay >/dev/null 2>&1; then
HAVEAUPLAY=true
fi
HAVEAUDIOPLAY=false
if type audioplay >/dev/null 2>&1; then
HAVEAUDIOPLAY=true
fi
HAVEESDPLAY=false
if type esdplay >/dev/null 2>&1; then
HAVEESDPLAY=true
fi
if [ -z "${AUDIOPLAYER}" ]; then
if [ -n "${AUDIOSERVER}" ]; then
if ${HAVEAUPLAY} ; then
AUDIOPLAYER="auplay -v 20"
fi
elif ${HAVEESDPLAY} ; then
# XXX ESound is actually a dead-end....
AUDIOPLAYER="esdplay"
if [ -z "$ESPEAKER" ]; then
# n.b.: a hostname alias....
ESPEAKER="audiosrvr"; export ESPEAKER
fi
elif [ -w /dev/audio ]; then
if ${HAVEAUDIOPLAY} ; then
AUDIOPLAYER="audioplay"
fi
fi
fi
if [ -z "${AUDIOPLAYER}" ]; then
# avoid trying to run audio files...
AUDIOPLAYER=":"
fi
export AUDIOPLAYER
RNINIT="-v -M -S -T -i=8 -g2" ; export RNINIT
TRNINIT=${HOME}/.trninit; export TRNINIT
# This is supposedly mostly for pine....
#
if [ -x ${PKG}/bin/ispell ]; then
SPELL=${PKG}"/bin/ispell -l"
export SPELL
fi
# set terminal type and tty settings, etc....
#
if ${ISATTY} && [ -z "${XDG_CURRENT_DESKTOP}" ]; then
echo "Re-setting terminal preferences...."
# turn this off by default, turn it on by hand in one main window?
mesg n
if [ -r "${HOME}/.stty" ]; then
. ${HOME}/.stty
else
# XXX the erase+intr bit should be terminal dependent instead of trying
# to see if we have to undo it based on terminal type later
#
stty erase '^h' intr '^?' kill '^u' -ixany echo echoe echok
# a separate command as it is a non-standard parameter
stty status '^t' 2>/dev/null || echo "Sorry, probably no SIGNIFO support on this system."
fi
if [ "${EMACS}" = t -o "${TERM}" = emacs ]; then # there is also ${INSIDE_EMACS}
echo "Turning off echo for an emacs shell...."
stty -echo
fi
case "${TERM}" in
""|network|dialup|unknown|none)
# n.b.: a function may not work to set an env var, see
# the note above the definition of ~/.shrc:get_newterm()
get_newterm
;;
*)
# xxx hmmm.... this could just use $TERMTESTCMD (also from
# ~/.shrc), after setting $_ttytype, but doing so would make
# showing the warning notice impossible...
#
if ${HAVETPUT} ; then
if tput longname > /dev/null; then
: # all is well....
else
echo "NOTICE: the preset TERM=${TERM} is unknown...";
TERM=unknown;
get_newterm
fi
elif type tset >/dev/null 2>&1; then
# n.b.: this asks the user interactively if TERM is unknown...
eval `tset -s`
# xxx if we want this, we get it later!