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
31 *:$i:*) val=${val%%:$i:*}:${val#*:$i:} ;;
32 $i:*) val=${val#$i:} ;;
33 *:$i) val=${val%:$i} ;;
38 l) val=${new#:}${val:+:$val} ;;
39 r) val=${val:+$val:}${new#:} ;;
41 case $change in t) eval $var=\$val ;; esac
44 ## __mdw_programp NAME
46 ## Does NAME exist as an executable program?
47 __mdw_programp () { type >/dev/null 2>&1 "$1"; }
49 ## __mdw_setconf VAR CONF [DEFAULT]
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.
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"
60 ## __mdw_export_if_defined VAR ...
62 ## If VARs are defined, then export them.
63 __mdw_export_if_defined () {
67 case $t in t) export $var ;; esac
71 ###--------------------------------------------------------------------------
72 ### Other preliminaries.
74 ## Work out my home directory, resolving symbolic links.
75 HOME=$(cd "$HOME"; pwd -P)
76 case ${SCHROOT_SESSION_ID+t} in t) ;; *) cd "$HOME" ;; esac
78 ## CDE's session structure is demented and doesn't leave us with a proper
79 ## logout hook, so synthesize one here.
80 case ${DT+t} in t) trap "source $HOME/.shell-logout" EXIT; esac
82 ###--------------------------------------------------------------------------
83 ### Set some basic paths.
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 \
93 /opt/nfast/bin /opt/nfast/sbin
95 ## If we have Plan 9 from User Space, then add that in.
96 for i in /opt/plan9 /usr/local/plan9; do
98 PLAN9=$i; export PLAN9
99 __mdw_addto PATH r $i/bin
104 ## Check for some standard path hacks.
106 __mdw_addto PATH l "$HOME"/bin/hacks/$i
109 ###--------------------------------------------------------------------------
110 ### Some other preliminaries.
112 ## Establish a temporary directory.
115 *) if __mdw_programp tmpdir; then eval $(tmpdir -b); fi
117 TMP=$TMPDIR; export TMP
119 ## Sensible umask if users have their own groups.
122 ###--------------------------------------------------------------------------
123 ### Text editor configuration.
126 emacs_startup_args="--no-site-file --mdw-fast-startup -nw"
128 "emacs24 $emacs_startup_args" \
129 "emacs23 $emacs_startup_args" \
130 "emacs22 $emacs_startup_args" \
131 "emacs21 $emacs_startup_args" \
137 if __mdw_programp "$name"; then MDW_EDITOR=$ed; break; fi
139 EDITOR=mdw-editor VISUAL=mdw-editor
140 export EDITOR VISUAL MDW_EDITOR
141 unset ed emacs_startup_args
143 ###--------------------------------------------------------------------------
144 ### Locale configuration.
146 case ${LC_MDWSSHLANG+t},${DISPLAY+t} in
151 __mdw_setconf LANG x-ctype POSIX
154 : LANG=${LC_CTYPE-${LC_ALL-$(mdw-conf console-ctype POSIX)}}
155 case "$TERM,$(tty)" in
157 if { vt-is-UTF8 || kbd_mode | grep UTF-8; } >/dev/null 2>&1; then
162 LANG=${LANG%.*}$ctype
170 LC_COLLATE=POSIX; export LC_COLLATE
173 t) LC_MDWSSHLANG=$LANG; export LC_MDWSSHLANG ;;
176 ###--------------------------------------------------------------------------
179 ## Choose a sensible pager.
181 for pg in less more; do
182 if __mdw_programp "$pg"; then MDW_PAGER=$(command -v "$pg"); break; fi
184 PAGER=mdw-pager METAMAIL_PAGER=mdw-pager
185 export MDW_PAGER PAGER METAMAIL_PAGER
189 case ${LC_CTYPE-$LANG} in
190 *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;;
191 *) LESSCHARSET=latin1 ;;
194 if __mdw_programp global; then
195 LESSGLOBALTAGS=global
196 export LESSGLOBALTAGS
199 ## Get Debian `groff' to produce control sequences rather than overstriking.
200 GROFF_SGR=t; export GROFF_SGR
202 ###--------------------------------------------------------------------------
203 ### Miscellaneous things.
205 ## Mail and general identification.
206 __mdw_setconf MAIL mailbox /var/mail/mdw
207 __mdw_setconf EMAIL email mdw@distorted.org.uk
208 NAME="Mark Wooding"; export NAME
211 __mdw_setconf NNTPSERVER nntp-server
213 ## Some programs want to know the hostname.
214 case ${HOST+t} in t) ;; *) HOST=$(hostname); export HOST; esac
216 ## HTTP and FTP proxies.
217 http=$(mdw-conf http-proxy none)
218 case "${http_proxy-none},$http" in
220 none,*) http_proxy=http://$http/; export http_proxy ;;
222 https=$(mdw-conf https-proxy none)
223 case "${https_proxy-none},$https,${http_proxy-none}" in
225 none,none,*) https_proxy=$http_proxy; export https_proxy ;;
226 none,*,*) https_proxy=http://$https/; export ftp_proxy ;;
228 ftp=$(mdw-conf ftp-proxy none)
229 case "${ftp_proxy-none},$ftp,${http_proxy-none}" in
231 none,none,*) ftp_proxy=$http_proxy; export ftp_proxy ;;
232 none,*,*) ftp_proxy=http://$ftp/; export ftp_proxy ;;
236 ## Ncurses programs should use the Unicode box-drawing characters because the
237 ## alternative character set stuff isn't supported well.
238 NCURSES_NO_UTF8_ACS=1; export NCURSES_NO_UTF8_ACS
240 ## Shut up Perl's readline machinery.
241 PERL_READLINE_NOWARN=yes; export PERL_READLINE_NOWARN
243 ## If we have `distcc' then tell `ccache' to use it.
244 if __mdw_programp distcc; then CCACHE_PREFIX=distcc; export CCACHE_PREFIX; fi
246 ## Choose a sensible web browser. If we have a display, try to pick a
248 set -- elinks w3m lynx
250 t) set -- mdw-iceweasel mdw-chrome iceweasel firefox "$@" ;;
253 if __mdw_programp $b; then BROWSER=$b; export BROWSER; break; fi
257 ## Acquiring root privileges. This is mainly the job of `bashrc', but we
258 ## cache the mechanism here.
259 __mdw_setconf __MDW_ROOTLY rootly
260 BECOME="--preserve-environment"; export BECOME
262 ## It's useful to see the little sigils in `ls'.
263 case ${LS_OPTIONS+t} in t) ;; *) LS_OPTIONS="-F"; export LS_OPTIONS; esac
265 ## Settings for BBC BASIC listing.
266 export BASCAT="-l +n"
268 ## Version control hacking.
269 CVS_RSH=ssh; export CVS_RSH
270 __mdw_setconf CVSROOT cvs-root
271 __mdw_setconf SVNROOT svn-root
272 P4CONFIG=.p4; export P4CONFIG
274 ## Help X programs find their resources.
275 XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S"
276 export XUSERFILESEARCHPATH
278 ## Make OpenOffice.org do its thing properly.
279 OOO_FORCE_DESKTOP=gnome; export OOO_FORCE_DESKTOP
281 ## Hack Qt-ish things to be unstoatly.
282 QT_QPA_PLATFORMTHEME=gtk2; export QT_QPA_PLATFORMTHEME
283 QT_AUTO_SCREEN_SCALE_FACTOR=0; export QT_AUTO_SCREEN_SCALE_FACTOR
285 ## Use X11 input method (including compose key sequences) everywhere.
286 GTK_IM_MODULE=xim; export GTK_IM_MODULE
287 QT_IM_MODULE=xim; export QT_IM_MODULE
289 ## Don't hide scrollbars.
290 GTK_OVERLAY_SCROLLING=0; export GTK_OVERLAY_SCROLLING
292 ## Rust Cargo things.
293 CARGO_HOME=$HOME/.cache/cargo; export CARGO_HOME
296 PS_PERSONALITY=gnu; export PS_PERSONALITY
298 ## Configure Debian building.
299 DEB_BUILD_OPTIONS="parallel=$(mdw-conf make-parallel 4)"
300 export DEB_BUILD_OPTIONS
302 ## Turn off angry fruit salad error messages from things.
303 DPKG_COLORS=never; export DPKG_COLORS
304 GCC_COLORS=; export GCC_COLORS
305 CCC_OVERRIDE_OPTIONS="#^-fno-color-diagnostics"; export CCC_OVERRIDE_OPTIONS
307 ## Local library directories.
308 __mdw_addto PERLLIB l $HOME/lib/perl; __mdw_export_if_defined PERLLIB
309 __mdw_addto PYTHONPATH l $HOME/lib/python; __mdw_export_if_defined PYTHONPATH
311 ## Disable core dumps.
314 ###--------------------------------------------------------------------------
315 ### Authentication and SSH hacking.
317 ## Start an authentication agent. This is unnecessarily fiddly. If there's
318 ## a Gnome keyring server then we should use that; unfortunately, it may not
319 ## yet have had a chance to populate the environment with its settings, so we
320 ## go off and fetch them.
321 if { { [ "$GNOME_KEYRING_CONTROL" ] &&
322 [ -s "$GNOME_KEYRING_CONTROL" ]; } ||
323 { [ "$DBUS_SESSION_BUS_ADDRESS" ] &&
324 __mdw_programp gnome-keyring-daemon; }; } &&
325 stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null)
328 export SSH_AUTH_SOCK GPG_AGENT_INFO
331 ## If we still don't have an agent then start one with a stable name.
332 eval $(start-ssh-agent -b)
334 ## Decide whether this session should be considered `secure'. A session is
335 ## secure if it's on a secure TTY, but there are lots of ways of finding out
336 ## which TTYs are secure.
337 if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] ||
338 ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}"
339 { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } ||
340 { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } &&
341 egrep "$devtty" $sectty >/dev/null; } ||
342 { [ -e /etc/default/login ] &&
343 egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } ||
344 case "${tty#/dev/}" in
345 console|systty|tty[0-9]) true ;;
349 __mdw_sechost=$HOST; export __mdw_sechost
352 ## Start a passphrase pixie if there is one and it's not already running.
353 if pixie --version >/dev/null 2>&1; then
354 mkdir -p "$HOME/.catacomb"
355 pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie}
356 if [ -S "$pixie" ] && pixie -C help >/dev/null 2>&1; then
359 pixie -d 2>>"$HOME/.catacomb/pixie.log"
360 __mdw_started_pixie=yes
364 ###--------------------------------------------------------------------------
365 ### Finishing touches.
367 ## For old-fashioned Bourne-ish shells, set up per-shell definitions.
368 ENV=$HOME/.shrc; export ENV
370 ## If there's a local hook then run it.
371 if [ -f "$HOME/.profile-local" ]; then . "$HOME/.profile-local"; fi
373 ###----- That's all, folks --------------------------------------------------