3 ### Session startup things.
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
9 ###--------------------------------------------------------------------------
10 ### Utility functions.
12 ## __mdw_addto VAR DIR PATH ...
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
23 local var=$1 val dir=$2 new="" change=nil
27 case "$new:" in *:$i:*) continue;; esac
28 if ! [ -d $i ]; then continue; fi
30 "") val=$i change=t; continue ;;
32 *:$i:*) val=${val%%:$i:*}:${val#*:$i:} ;;
33 $i:*) val=${val#$i:} ;;
34 *:$i) val=${val%:$i} ;;
39 l) val=${new#:}:$val ;;
42 case $change in t) eval $var=\$val ;; esac
45 ## __mdw_programp NAME
47 ## Does NAME exist as an executable program?
48 __mdw_programp () { type >/dev/null 2>&1 "$1"; }
50 ## __mdw_setconf VAR CONF [DEFAULT]
52 ## If CONF is defined in `~/.mdw.conf' then set VAR to its value; otherwise,
53 ## set VAR to DEFAULT, if given; otherwise, do nothing at all.
55 local var=$1 conf=$2 val; shift 2
56 if val=$(mdw-conf 2>/dev/null "$conf" "$@"); then
57 eval "$var=\$val; export $var"
61 ###--------------------------------------------------------------------------
62 ### Other preliminaries.
64 ## Work out my home directory, resolving symbolic links.
65 HOME=$(cd "$HOME"; pwd -P)
66 case ${SCHROOT_SESSION_ID+t} in t) ;; *) cd "$HOME" ;; esac
68 ## CDE's session structure is demented and doesn't leave us with a proper
69 ## logout hook, so synthesize one here.
70 case ${DT+t} in t) trap "source $HOME/.shell-logout" EXIT; esac
72 ###--------------------------------------------------------------------------
73 ### Set some basic paths.
79 /usr/local/bin /usr/local/sbin /usr/local/games \
80 /usr/bin /usr/sbin /usr/games \
81 /usr/X11R6/bin /usr/local/X11R6/bin \
83 /opt/nfast/bin /opt/nfast/sbin
85 ## If we have Plan 9 from User Space, then add that in.
86 for i in /opt/plan9 /usr/local/plan9; do
88 PLAN9=$i; export PLAN9
89 __mdw_addto PATH r $i/bin
94 ## Check for some standard path hacks.
96 __mdw_addto PATH l "$HOME"/bin/hacks/$i
99 ###--------------------------------------------------------------------------
100 ### Some other preliminaries.
102 ## Establish a temporary directory.
105 *) if __mdw_programp tmpdir; then eval $(tmpdir -b); fi
107 TMP=$TMPDIR; export TMP
109 ## Sensible umask if users have their own groups.
112 ###--------------------------------------------------------------------------
113 ### Text editor configuration.
116 emacs_startup_args="--no-site-file --mdw-fast-startup -nw"
118 "emacs24 $emacs_startup_args" \
119 "emacs23 $emacs_startup_args" \
120 "emacs22 $emacs_startup_args" \
121 "emacs21 $emacs_startup_args" \
127 if __mdw_programp "$name"; then MDW_EDITOR=$ed; break; fi
129 EDITOR=mdw-editor VISUAL=mdw-editor
130 export EDITOR VISUAL MDW_EDITOR
131 unset ed emacs_startup_args
133 ###--------------------------------------------------------------------------
134 ### Locale configuration.
136 case ${LC_MDWSSHLANG+t},${DISPLAY+t} in
141 __mdw_setconf LANG x-ctype POSIX
144 : LANG=${LC_CTYPE-${LC_ALL-$(mdw-conf console-ctype POSIX)}}
145 case "$TERM,$(tty)" in
147 if { vt-is-UTF8 || kbd_mode | grep UTF-8; } >/dev/null 2>&1; then
152 LANG=${LANG%.*}$ctype
160 LC_COLLATE=POSIX; export LC_COLLATE
163 t) LC_MDWSSHLANG=$LANG; export LC_MDWSSHLANG ;;
166 ###--------------------------------------------------------------------------
169 ## Choose a sensible pager.
171 for pg in less more; do
172 if __mdw_programp "$pg"; then MDW_PAGER=$(command -v "$pg"); break; fi
174 PAGER=mdw-pager METAMAIL_PAGER=mdw-pager
175 export MDW_PAGER PAGER METAMAIL_PAGER
179 LESS="-iqgRh1j.3FSX"; export LESS
180 LESSOPEN="|lesspipe.sh %s"; export LESSOPEN
181 case ${LC_CTYPE-$LANG} in
182 *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;;
183 *) LESSCHARSET=latin1 ;;
186 if __mdw_programp global; then
187 LESSGLOBALTAGS=global
188 export LESSGLOBALTAGS
191 ###--------------------------------------------------------------------------
192 ### Miscellaneous things.
194 ## Mail and general identification.
195 __mdw_setconf MAIL mailbox /var/mail/mdw
196 __mdw_setconf EMAIL email mdw@distorted.org.uk
197 NAME="Mark Wooding"; export NAME
200 __mdw_setconf NNTPSERVER nntp-server
202 ## Some programs want to know the hostname.
203 case ${HOST+t} in t) ;; *) HOST=$(hostname); export HOST; esac
205 ## HTTP and FTP proxies.
206 http=$(mdw-conf http-proxy none)
207 case "${http_proxy-none},$http" in
209 none,*) http_proxy=http://$http/; export http_proxy ;;
211 https=$(mdw-conf https-proxy none)
212 case "${https_proxy-none},$https,${http_proxy-none}" in
214 none,none,*) https_proxy=$http_proxy; export https_proxy ;;
215 none,*,*) https_proxy=http://$https/; export ftp_proxy ;;
217 ftp=$(mdw-conf ftp-proxy none)
218 case "${ftp_proxy-none},$ftp,${http_proxy-none}" in
220 none,none,*) ftp_proxy=$http_proxy; export ftp_proxy ;;
221 none,*,*) ftp_proxy=http://$ftp/; export ftp_proxy ;;
225 ## Ncurses programs should use the Unicode box-drawing characters because the
226 ## alternative character set stuff isn't supported well.
227 NCURSES_NO_UTF8_ACS=1; export NCURSES_NO_UTF8_ACS
229 ## Shut up Perl's readline machinery.
230 PERL_READLINE_NOWARN=yes; export PERL_READLINE_NOWARN
232 ## If we have `distcc' then tell `ccache' to use it.
233 if __mdw_programp distcc; then CCACHE_PREFIX=distcc; export CCACHE_PREFIX; fi
235 ## Choose a sensible web browser. If we have a display, try to pick a
237 set -- elinks w3m lynx
239 t) set -- chromium mdw-iceweasel mdw-chrome iceweasel firefox "$@" ;;
242 if __mdw_programp $b; then BROWSER=$b; export BROWSER; break; fi
246 ## Acquiring root privileges. This is mainly the job of `bashrc', but we
247 ## cache the mechanism here.
248 __mdw_setconf __MDW_ROOTLY rootly
249 BECOME="--preserve-environment"; export BECOME
251 ## It's useful to see the little sigils in `ls'.
252 case ${LS_OPTIONS+t} in t) ;; *) LS_OPTIONS="-F"; export LS_OPTIONS; esac
254 ## Settings for BBC BASIC listing.
255 export BASCAT="-l +n"
257 ## Version control hacking.
258 CVS_RSH=ssh; export CVS_RSH
259 __mdw_setconf CVSROOT cvs-root
260 __mdw_setconf SVNROOT svn-root
261 P4CONFIG=.p4; export P4CONFIG
263 ## Help X programs find their resources.
264 XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S"
265 export XUSERFILESEARCHPATH
267 ## Make OpenOffice.org do its thing properly.
268 OOO_FORCE_DESKTOP=gnome; export OOO_FORCE_DESKTOP
270 ## Hack Qt-ish things to be unstoatly.
271 QT_STYLE_OVERRIDE=gtk2; export QT_STYLE_OVERRIDE
273 ## Use X11 input method (including compose key sequences) everywhere.
274 GTK_IM_MODULE=xim; export GTK_IM_MODULE
275 QT_IM_MODULE=xim; export QT_IM_MODULE
278 PS_PERSONALITY=gnu; export PS_PERSONALITY
280 ## Disable core dumps.
283 ###--------------------------------------------------------------------------
284 ### Authentication and SSH hacking.
286 ## Start an authentication agent. This is unnecessarily fiddly. If there's
287 ## a Gnome keyring server then we should use that; unfortunately, it may not
288 ## yet have had a chance to populate the environment with its settings, so we
289 ## go off and fetch them.
290 if { { [ "$GNOME_KEYRING_CONTROL" ] &&
291 [ -s "$GNOME_KEYRING_CONTROL" ]; } ||
292 { [ "$DBUS_SESSION_BUS_ADDRESS" ] &&
293 __mdw_programp gnome-keyring-daemon; }; } &&
294 stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null)
297 export SSH_AUTH_SOCK GPG_AGENT_INFO
300 ## If we still don't have an agent then start one with a stable name.
301 eval $(start-ssh-agent -b)
303 ## Decide whether this session should be considered `secure'. A session is
304 ## secure if it's on a secure TTY, but there are lots of ways of finding out
305 ## which TTYs are secure.
306 if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] ||
307 ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}"
308 { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } ||
309 { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } &&
310 egrep "$devtty" $sectty >/dev/null; } ||
311 { [ -e /etc/default/login ] &&
312 egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } ||
313 case "${tty#/dev/}" in
314 console|systty|tty[0-9]) true ;;
318 __mdw_sechost=$HOST; export __mdw_sechost
321 ## Start a passphrase pixie if there is one and it's not already running.
322 if pixie --version >/dev/null 2>&1; then
323 mkdir -p "$HOME/.catacomb"
324 pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie}
325 if [ -S "$pixie" ] && pixie -C help >/dev/null 2>&1; then
328 pixie -d 2>>"$HOME/.catacomb/pixie.log"
329 __mdw_started_pixie=yes
333 ###--------------------------------------------------------------------------
334 ### Finishing touches.
336 ## For old-fashioned Bourne-ish shells, set up per-shell definitions.
337 ENV=$HOME/.shrc; export ENV
339 ## If there's a local hook then run it.
340 if [ -f "$HOME/.profile-local" ]; then . "$HOME/.profile-local"; fi
342 ###----- That's all, folks --------------------------------------------------