chiark / gitweb /
e46e627b76ed5aa9acb2f0d1dc3ca68fdf27c70d
[profile] / dot / profile
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
30       "") val=$i change=t; continue ;;
31       $i) continue ;;
32       *:$i:*) val=${val%%:$i:*}:${val#*:$i:} ;;
33       $i:*) val=${val#$i:} ;;
34       *:$i) val=${val%:$i} ;;
35     esac
36     new=$new:$i change=t
37   done
38   case $dir in
39     l) val=${new#:}:$val ;;
40     r) val=$val$new ;;
41   esac
42   case $change in t) eval $var=\$val ;; esac
43 }
44
45 ## __mdw_programp NAME
46 ##
47 ## Does NAME exist as an executable program?
48 __mdw_programp () { type >/dev/null 2>&1 "$1"; }
49
50 ## __mdw_setconf VAR CONF [DEFAULT]
51 ##
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.
54 __mdw_setconf () {
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"
58   fi
59 }
60
61 ###--------------------------------------------------------------------------
62 ### Other preliminaries.
63
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
67
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
71
72 ###--------------------------------------------------------------------------
73 ### Set some basic paths.
74
75 ## The main path.
76 export PATH
77 __mdw_addto PATH l \
78   "$HOME"/bin \
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 \
82   /bin /sbin \
83   /opt/nfast/bin /opt/nfast/sbin
84
85 ## If we have Plan 9 from User Space, then add that in.
86 if [ -d /usr/local/plan9 ]; then
87   PLAN9=/usr/local/plan9; export PLAN9
88   __mdw_addto PATH r $PLAN9/bin
89 fi
90
91 ## Check for some standard path hacks.
92 for i in ccache; do
93   __mdw_addto PATH l "$HOME"/bin/hacks/$i
94 done
95
96 ###--------------------------------------------------------------------------
97 ### Some other preliminaries.
98
99 ## Establish a temporary directory.
100 case ${TMPDIR+t} in
101   t) ;;
102   *) if __mdw_programp tmpdir; then eval $(tmpdir -b); fi
103 esac
104 TMP=$TMPDIR; export TMP
105
106 ## Sensible umask if users have their own groups.
107 umask 002
108
109 ###--------------------------------------------------------------------------
110 ### Text editor configuration.
111
112 MDW_EDITOR=ed
113 emacs_startup_args="--no-site-file --mdw-fast-startup -nw"
114 for ed in \
115   "emacs24 $emacs_startup_args" \
116   "emacs23 $emacs_startup_args" \
117   "emacs22 $emacs_startup_args" \
118   "emacs21 $emacs_startup_args" \
119   zile mg \
120   "emacs -nw" \
121   vi pico nano ae
122 do
123   name=${ed%% *}
124   if __mdw_programp "$name"; then MDW_EDITOR=$ed; break; fi
125 done
126 EDITOR=mdw-editor VISUAL=mdw-editor
127 export EDITOR VISUAL MDW_EDITOR
128 unset ed emacs_startup_args
129
130 ###--------------------------------------------------------------------------
131 ### Locale configuration.
132
133 case ${DISPLAY+t} in
134   t)
135     __mdw_setconf LANG x-ctype POSIX
136     ;;
137   *)
138     : LANG=${LC_CTYPE-${LC_ALL-$(mdw-conf console-ctype POSIX)}}
139     case "$TERM,$(tty)" in
140       linux,/dev/tty*)
141         if { vt-is-UTF8 || kbd_mode | grep UTF-8; } >/dev/null 2>&1; then
142           ctype=.utf8
143         else
144           ctype=
145         fi
146         LANG=${LANG%.*}$ctype
147         ;;
148     esac
149     ;;
150 esac
151 unset LC_ALL
152 export LANG
153
154 LC_COLLATE=POSIX; export LC_COLLATE
155
156 ###--------------------------------------------------------------------------
157 ### Pagers.
158
159 ## Choose a sensible pager.
160 MDW_PAGER=more
161 for pg in less more; do
162   if __mdw_programp "$pg"; then MDW_PAGER=$(command -v "$pg"); break; fi
163 done
164 PAGER=mdw-pager METAMAIL_PAGER=mdw-pager
165 export MDW_PAGER PAGER METAMAIL_PAGER
166 unset pg
167
168 ## Configure `less'.
169 LESS="-iqgRh1j.3FSX"; export LESS
170 LESSOPEN="|lesspipe.sh %s"; export LESSOPEN
171 case ${LC_CTYPE-$LANG} in
172   *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;;
173   *) LESSCHARSET=latin1 ;;
174 esac
175 export LESSCHARSET
176 if __mdw_programp global; then
177   LESSGLOBALTAGS=global
178   export LESSGLOBALTAGS
179 fi
180
181 ###--------------------------------------------------------------------------
182 ### Miscellaneous things.
183
184 ## Mail and general identification.
185 __mdw_setconf MAIL mailbox /var/mail/mdw
186 __mdw_setconf EMAIL email mdw@distorted.org.uk
187 NAME="Mark Wooding"; export NAME
188
189 ## News server.
190 __mdw_setconf NNTPSERVER nntp-server
191
192 ## Some programs want to know the hostname.
193 case ${HOST+t} in t) ;; *) HOST=$(hostname); export HOST; esac
194
195 ## HTTP and FTP proxies.
196 http=$(mdw-conf http-proxy none)
197 case "${http_proxy-none},$http" in
198   *,none) ;;
199   none,*) http_proxy=http://$http/; export http_proxy ;;
200 esac
201 ftp=$(mdw-conf ftp-proxy none)
202 case "${ftp_proxy-none},$ftp,${http_proxy-none}" in
203   *,none,none) ;;
204   none,none,*) ftp_proxy=$http_proxy; export ftp_proxy ;;
205   none,*,*) ftp_proxy=http://$ftp/; export ftp_proxy ;;
206 esac
207 unset http ftp
208
209 ## Ncurses programs should use the Unicode box-drawing characters because the
210 ## alternative character set stuff isn't supported well.
211 NCURSES_NO_UTF8_ACS=1; export NCURSES_NO_UTF8_ACS
212
213 ## Shut up Perl's readline machinery.
214 PERL_READLINE_NOWARN=yes; export PERL_READLINE_NOWARN
215
216 ## If we have `distcc' then tell `ccache' to use it.
217 if __mdw_programp distcc; then CCACHE_PREFIX=distcc; export CCACHE_PREFIX; fi
218
219 ## Choose a sensible web browser.  If we have a display, try to pick a
220 ## graphical one.
221 set -- elinks w3m lynx
222 case ${DISPLAY+t} in
223   t) set -- chromium mdw-iceweasel mdw-chrome iceweasel firefox "$@" ;;
224 esac
225 for b in "$@"; do
226   if __mdw_programp $b; then BROWSER=$b; export BROWSER; break; fi
227 done
228 unset b
229
230 ## Acquiring root privileges.  This is mainly the job of `bashrc', but we
231 ## cache the mechanism here.
232 __mdw_setconf __MDW_ROOTLY rootly
233 BECOME="--preserve-environment"; export BECOME
234
235 ## It's useful to see the little sigils in `ls'.
236 case ${LS_OPTIONS+t} in t) ;; *) LS_OPTIONS="-F"; export LS_OPTIONS; esac
237
238 ## Settings for BBC BASIC listing.
239 export BASCAT="-l +n"
240
241 ## Version control hacking.
242 CVS_RSH=ssh; export CVS_RSH
243 __mdw_setconf CVSROOT cvs-root
244 __mdw_setconf SVNROOT svn-root
245 P4CONFIG=.p4; export P4CONFIG
246
247 ## Help X programs find their resources.
248 XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S"
249 export XUSERFILESEARCHPATH
250
251 ## Make OpenOffice.org do its thing properly.
252 OOO_FORCE_DESKTOP=gnome; export OOO_FORCE_DESKTOP
253
254 ## Hack Qt-ish things to be unstoatly.
255 QT_STYLE_OVERRIDE=gtk2; export QT_STYLE_OVERRIDE
256
257 ## Configure `ps'.
258 PS_PERSONALITY=gnu; export PS_PERSONALITY
259
260 ## Disable core dumps.
261 ulimit -S -c 0
262
263 ###--------------------------------------------------------------------------
264 ### Authentication and SSH hacking.
265
266 ## Start an authentication agent.  This is unnecessarily fiddly.  If there's
267 ## a Gnome keyring server then we should use that; unfortunately, it may not
268 ## yet have had a chance to populate the environment with its settings, so we
269 ## go off and fetch them.
270 if { { [ "$GNOME_KEYRING_CONTROL" ] &&
271        [ -s "$GNOME_KEYRING_CONTROL" ]; } ||
272      { [ "$DBUS_SESSION_BUS_ADDRESS" ] &&
273        __mdw_programp gnome-keyring-daemon; }; } &&
274    stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null)
275 then
276   eval "$stuff"
277   export SSH_AUTH_SOCK GPG_AGENT_INFO
278 fi
279
280 ## If we still don't have an agent then start one with a stable name.
281 eval $(start-ssh-agent -b)
282
283 ## Decide whether this session should be considered `secure'.  A session is
284 ## secure if it's on a secure TTY, but there are lots of ways of finding out
285 ## which TTYs are secure.
286 if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] ||
287    ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}"
288      { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } ||
289          { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } &&
290        egrep "$devtty" $sectty >/dev/null; } ||
291      { [ -e /etc/default/login ] &&
292        egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } ||
293      case "${tty#/dev/}" in
294        console|systty|tty[0-9]) true ;;
295        *) false ;;
296      esac )
297 then
298   __mdw_sechost=$HOST; export __mdw_sechost
299 fi
300
301 ## Start a passphrase pixie if there is one and it's not already running.
302 if pixie --version >/dev/null 2>&1; then
303   mkdir -p "$HOME/.catacomb"
304   pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie}
305   if [ -S "$pixie" ] && pixie -C help >/dev/null 2>&1; then
306     :
307   else
308     pixie -d 2>>"$HOME/.catacomb/pixie.log"
309     __mdw_started_pixie=yes
310   fi
311 fi
312
313 ###--------------------------------------------------------------------------
314 ### Finishing touches.
315
316 ## For old-fashioned Bourne-ish shells, set up per-shell definitions.
317 ENV=$HOME/.shrc; export ENV
318
319 ## If there's a local hook then run it.
320 if [ -f "$HOME/.profile-local" ]; then . "$HOME/.profile-local"; fi
321
322 ###----- That's all, folks --------------------------------------------------