el/dot-emacs.el (Man-getpage-in-background): Don't try to split atoms.
[profile] / dot / profile
CommitLineData
74a53e28
MW
1### -*-sh-*-
2###
3### Session startup things.
4
5## The shell-specific hook will run us if it thinks we haven't been run
6## before. We should therefore let it know.
7__mdw_profile=t; export __mdw_profile
8
9###--------------------------------------------------------------------------
10### Utility functions.
11
12## __mdw_addto VAR DIR PATH ...
13##
14## VAR is the name of a PATH-like environment variable (i.e., one which
15## contains a sequence of pathnames separated by colons). DIR is either `l'
16## or `r'. The PATHs are pathnames. Those PATHs which correspond to
17## existing directories but which aren't currently named in the variable are
18## added to the left or right (depending on DIR) of VAR. The relative order
19## of PATHs added in the same invokation is the same as the order they
20## appeared in PATHs: the DIR argument only affects which end of the VAR they
21## get added to.
22__mdw_addto () {
23 local var=$1 val dir=$2 new="" change=nil
24 eval val=\$$var
25 shift 2
26 for i in "$@"; do
27 case "$new:" in *:$i:*) continue;; esac
28 if ! [ -d $i ]; then continue; fi
29 case "$val" in
74a53e28
MW
30 $i) continue ;;
31 *:$i:*) val=${val%%:$i:*}:${val#*:$i:} ;;
32 $i:*) val=${val#$i:} ;;
33 *:$i) val=${val%:$i} ;;
34 esac
35 new=$new:$i change=t
36 done
37 case $dir in
4c085f9e
MW
38 l) val=${new#:}${val:+:$val} ;;
39 r) val=${val:+$val:}${new#:} ;;
74a53e28
MW
40 esac
41 case $change in t) eval $var=\$val ;; esac
42}
43
44## __mdw_programp NAME
45##
46## Does NAME exist as an executable program?
47__mdw_programp () { type >/dev/null 2>&1 "$1"; }
48
49## __mdw_setconf VAR CONF [DEFAULT]
50##
51## If CONF is defined in `~/.mdw.conf' then set VAR to its value; otherwise,
52## set VAR to DEFAULT, if given; otherwise, do nothing at all.
53__mdw_setconf () {
54 local var=$1 conf=$2 val; shift 2
55 if val=$(mdw-conf 2>/dev/null "$conf" "$@"); then
56 eval "$var=\$val; export $var"
57 fi
58}
59
dbf14608
MW
60## __mdw_export_if_defined VAR ...
61##
62## If VARs are defined, then export them.
63__mdw_export_if_defined () {
64 local var t
65 for var in "$@"; do
66 eval t=\${$var+t}
67 case $t in t) export $var ;; esac
68 done
69}
70
74a53e28
MW
71###--------------------------------------------------------------------------
72### Other preliminaries.
73
74## Work out my home directory, resolving symbolic links.
75HOME=$(cd "$HOME"; pwd -P)
76case ${SCHROOT_SESSION_ID+t} in t) ;; *) cd "$HOME" ;; esac
77
78## CDE's session structure is demented and doesn't leave us with a proper
79## logout hook, so synthesize one here.
80case ${DT+t} in t) trap "source $HOME/.shell-logout" EXIT; esac
81
82###--------------------------------------------------------------------------
83### Set some basic paths.
84
85## The main path.
86export PATH
87__mdw_addto PATH l \
88 "$HOME"/bin \
89 /usr/local/bin /usr/local/sbin /usr/local/games \
90 /usr/bin /usr/sbin /usr/games \
91 /usr/X11R6/bin /usr/local/X11R6/bin \
92 /bin /sbin \
93 /opt/nfast/bin /opt/nfast/sbin
94
95## If we have Plan 9 from User Space, then add that in.
8fd6f7da
MW
96for i in /opt/plan9 /usr/local/plan9; do
97 if [ -d $i ]; then
98 PLAN9=$i; export PLAN9
99 __mdw_addto PATH r $i/bin
100 break
101 fi
102done
74a53e28 103
b97b3f8e
MW
104## Check for some standard path hacks.
105for i in ccache; do
106 __mdw_addto PATH l "$HOME"/bin/hacks/$i
107done
108
74a53e28
MW
109###--------------------------------------------------------------------------
110### Some other preliminaries.
111
112## Establish a temporary directory.
113case ${TMPDIR+t} in
114 t) ;;
115 *) if __mdw_programp tmpdir; then eval $(tmpdir -b); fi
116esac
117TMP=$TMPDIR; export TMP
118
119## Sensible umask if users have their own groups.
120umask 002
121
122###--------------------------------------------------------------------------
123### Text editor configuration.
124
125MDW_EDITOR=ed
126emacs_startup_args="--no-site-file --mdw-fast-startup -nw"
127for ed in \
128 "emacs24 $emacs_startup_args" \
129 "emacs23 $emacs_startup_args" \
130 "emacs22 $emacs_startup_args" \
131 "emacs21 $emacs_startup_args" \
132 zile mg \
133 "emacs -nw" \
134 vi pico nano ae
135do
136 name=${ed%% *}
137 if __mdw_programp "$name"; then MDW_EDITOR=$ed; break; fi
138done
139EDITOR=mdw-editor VISUAL=mdw-editor
140export EDITOR VISUAL MDW_EDITOR
141unset ed emacs_startup_args
142
143###--------------------------------------------------------------------------
144### Locale configuration.
145
2c44f386
MW
146case ${LC_MDWSSHLANG+t},${DISPLAY+t} in
147 t,*)
148 LANG=$LC_MDWSSHLANG
149 ;;
150 ,t)
74a53e28
MW
151 __mdw_setconf LANG x-ctype POSIX
152 ;;
153 *)
154 : LANG=${LC_CTYPE-${LC_ALL-$(mdw-conf console-ctype POSIX)}}
155 case "$TERM,$(tty)" in
156 linux,/dev/tty*)
157 if { vt-is-UTF8 || kbd_mode | grep UTF-8; } >/dev/null 2>&1; then
2f27026a 158 ctype=.UTF-8
74a53e28
MW
159 else
160 ctype=
161 fi
162 LANG=${LANG%.*}$ctype
163 ;;
164 esac
165 ;;
166esac
167unset LC_ALL
168export LANG
169
170LC_COLLATE=POSIX; export LC_COLLATE
171
2c44f386
MW
172case ${LANG+t} in
173 t) LC_MDWSSHLANG=$LANG; export LC_MDWSSHLANG ;;
174esac
175
74a53e28
MW
176###--------------------------------------------------------------------------
177### Pagers.
178
179## Choose a sensible pager.
180MDW_PAGER=more
181for pg in less more; do
182 if __mdw_programp "$pg"; then MDW_PAGER=$(command -v "$pg"); break; fi
183done
184PAGER=mdw-pager METAMAIL_PAGER=mdw-pager
185export MDW_PAGER PAGER METAMAIL_PAGER
186unset pg
187
188## Configure `less'.
74a53e28
MW
189case ${LC_CTYPE-$LANG} in
190 *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;;
191 *) LESSCHARSET=latin1 ;;
192esac
193export LESSCHARSET
194if __mdw_programp global; then
195 LESSGLOBALTAGS=global
196 export LESSGLOBALTAGS
197fi
198
199###--------------------------------------------------------------------------
200### Miscellaneous things.
201
202## Mail and general identification.
203__mdw_setconf MAIL mailbox /var/mail/mdw
204__mdw_setconf EMAIL email mdw@distorted.org.uk
205NAME="Mark Wooding"; export NAME
206
207## News server.
208__mdw_setconf NNTPSERVER nntp-server
209
210## Some programs want to know the hostname.
211case ${HOST+t} in t) ;; *) HOST=$(hostname); export HOST; esac
212
213## HTTP and FTP proxies.
214http=$(mdw-conf http-proxy none)
215case "${http_proxy-none},$http" in
216 *,none) ;;
217 none,*) http_proxy=http://$http/; export http_proxy ;;
218esac
442bc88b
MW
219https=$(mdw-conf https-proxy none)
220case "${https_proxy-none},$https,${http_proxy-none}" in
221 *,none,none) ;;
222 none,none,*) https_proxy=$http_proxy; export https_proxy ;;
223 none,*,*) https_proxy=http://$https/; export ftp_proxy ;;
224esac
74a53e28
MW
225ftp=$(mdw-conf ftp-proxy none)
226case "${ftp_proxy-none},$ftp,${http_proxy-none}" in
227 *,none,none) ;;
228 none,none,*) ftp_proxy=$http_proxy; export ftp_proxy ;;
229 none,*,*) ftp_proxy=http://$ftp/; export ftp_proxy ;;
230esac
442bc88b 231unset http https ftp
74a53e28
MW
232
233## Ncurses programs should use the Unicode box-drawing characters because the
234## alternative character set stuff isn't supported well.
235NCURSES_NO_UTF8_ACS=1; export NCURSES_NO_UTF8_ACS
236
237## Shut up Perl's readline machinery.
238PERL_READLINE_NOWARN=yes; export PERL_READLINE_NOWARN
239
240## If we have `distcc' then tell `ccache' to use it.
241if __mdw_programp distcc; then CCACHE_PREFIX=distcc; export CCACHE_PREFIX; fi
242
243## Choose a sensible web browser. If we have a display, try to pick a
244## graphical one.
245set -- elinks w3m lynx
246case ${DISPLAY+t} in
94526c3f 247 t) set -- mdw-iceweasel mdw-chrome iceweasel firefox "$@" ;;
74a53e28
MW
248esac
249for b in "$@"; do
250 if __mdw_programp $b; then BROWSER=$b; export BROWSER; break; fi
251done
252unset b
253
254## Acquiring root privileges. This is mainly the job of `bashrc', but we
255## cache the mechanism here.
256__mdw_setconf __MDW_ROOTLY rootly
257BECOME="--preserve-environment"; export BECOME
258
259## It's useful to see the little sigils in `ls'.
260case ${LS_OPTIONS+t} in t) ;; *) LS_OPTIONS="-F"; export LS_OPTIONS; esac
261
262## Settings for BBC BASIC listing.
263export BASCAT="-l +n"
264
265## Version control hacking.
266CVS_RSH=ssh; export CVS_RSH
267__mdw_setconf CVSROOT cvs-root
268__mdw_setconf SVNROOT svn-root
269P4CONFIG=.p4; export P4CONFIG
270
271## Help X programs find their resources.
272XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S"
273export XUSERFILESEARCHPATH
274
275## Make OpenOffice.org do its thing properly.
276OOO_FORCE_DESKTOP=gnome; export OOO_FORCE_DESKTOP
277
278## Hack Qt-ish things to be unstoatly.
f1e393ff 279QT_QPA_PLATFORMTHEME=gtk2; export QT_QPA_PLATFORMTHEME
e3a7c1c2 280QT_AUTO_SCREEN_SCALE_FACTOR=0; export QT_AUTO_SCREEN_SCALE_FACTOR
74a53e28 281
eb174df8
MW
282## Use X11 input method (including compose key sequences) everywhere.
283GTK_IM_MODULE=xim; export GTK_IM_MODULE
284QT_IM_MODULE=xim; export QT_IM_MODULE
285
8308648a
MW
286## Don't hide scrollbars.
287GTK_OVERLAY_SCROLLING=0; export GTK_OVERLAY_SCROLLING
288
ab94ba6e
MW
289## Rust Cargo things.
290CARGO_HOME=$HOME/.cache/cargo; export CARGO_HOME
291
74a53e28
MW
292## Configure `ps'.
293PS_PERSONALITY=gnu; export PS_PERSONALITY
294
f9ef6491 295## Configure Debian building.
b0b75b94 296DEB_BUILD_OPTIONS="parallel=$(mdw-conf make-parallel 4)"
f9ef6491
MW
297export DEB_BUILD_OPTIONS
298
18045f11
MW
299## Turn off angry fruit salad error messages from things.
300DPKG_COLORS=never; export DPKG_COLORS
301GCC_COLORS=; export GCC_COLORS
302CCC_OVERRIDE_OPTIONS="#^-fno-color-diagnostics"; export CCC_OVERRIDE_OPTIONS
303
85bd3826
MW
304## Local library directories.
305__mdw_addto PERLLIB l $HOME/lib/perl; __mdw_export_if_defined PERLLIB
306__mdw_addto PYTHONPATH l $HOME/lib/python; __mdw_export_if_defined PYTHONPATH
307
74a53e28
MW
308## Disable core dumps.
309ulimit -S -c 0
310
311###--------------------------------------------------------------------------
312### Authentication and SSH hacking.
313
314## Start an authentication agent. This is unnecessarily fiddly. If there's
315## a Gnome keyring server then we should use that; unfortunately, it may not
316## yet have had a chance to populate the environment with its settings, so we
317## go off and fetch them.
318if { { [ "$GNOME_KEYRING_CONTROL" ] &&
319 [ -s "$GNOME_KEYRING_CONTROL" ]; } ||
320 { [ "$DBUS_SESSION_BUS_ADDRESS" ] &&
321 __mdw_programp gnome-keyring-daemon; }; } &&
322 stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null)
323then
324 eval "$stuff"
325 export SSH_AUTH_SOCK GPG_AGENT_INFO
326fi
327
328## If we still don't have an agent then start one with a stable name.
329eval $(start-ssh-agent -b)
330
331## Decide whether this session should be considered `secure'. A session is
332## secure if it's on a secure TTY, but there are lots of ways of finding out
333## which TTYs are secure.
334if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] ||
335 ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}"
336 { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } ||
337 { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } &&
338 egrep "$devtty" $sectty >/dev/null; } ||
339 { [ -e /etc/default/login ] &&
340 egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } ||
341 case "${tty#/dev/}" in
342 console|systty|tty[0-9]) true ;;
343 *) false ;;
344 esac )
345then
346 __mdw_sechost=$HOST; export __mdw_sechost
347fi
348
349## Start a passphrase pixie if there is one and it's not already running.
350if pixie --version >/dev/null 2>&1; then
351 mkdir -p "$HOME/.catacomb"
352 pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie}
353 if [ -S "$pixie" ] && pixie -C help >/dev/null 2>&1; then
354 :
355 else
356 pixie -d 2>>"$HOME/.catacomb/pixie.log"
357 __mdw_started_pixie=yes
358 fi
359fi
360
361###--------------------------------------------------------------------------
362### Finishing touches.
363
364## For old-fashioned Bourne-ish shells, set up per-shell definitions.
365ENV=$HOME/.shrc; export ENV
366
367## If there's a local hook then run it.
368if [ -f "$HOME/.profile-local" ]; then . "$HOME/.profile-local"; fi
369
370###----- That's all, folks --------------------------------------------------