chiark / gitweb /
el/dot-emacs.el: Apply `extend' setting to all(?) the applicable fonts.
[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       $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
38     l) val=${new#:}${val:+:$val} ;;
39     r) val=${val:+$val:}${new#:} ;;
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 () { command -v "$1" >/dev/null 2>&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
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
71 ###--------------------------------------------------------------------------
72 ### Other preliminaries.
73
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
77
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
81
82 ## Set the `runtime' directory.  This gets done automatically on a desktop
83 ## login, but not in, say, SSH, which causes anomalies.
84 if [ -d /run/user ]; then
85   : ${XDG_RUNTIME_DIR=/run/user/$(id -u)}; export XDG_RUNTIME_DIR
86 fi
87
88 ###--------------------------------------------------------------------------
89 ### Set some basic paths.
90
91 ## The main path.
92 export PATH
93 __mdw_addto PATH l \
94   "$HOME"/bin \
95   /usr/local/bin /usr/local/sbin /usr/local/games \
96   /usr/bin /usr/sbin /usr/games \
97   /usr/X11R6/bin /usr/local/X11R6/bin \
98   /bin /sbin \
99   /opt/nfast/bin /opt/nfast/sbin
100
101 ## If we have Plan 9 from User Space, then add that in.
102 for i in /opt/plan9 /usr/local/plan9; do
103   if [ -d $i ]; then
104     PLAN9=$i; export PLAN9
105     __mdw_addto PATH r $i/bin
106     break
107   fi
108 done
109
110 ## Check for some standard path hacks.
111 for i in ccache; do
112   __mdw_addto PATH l "$HOME"/bin/hacks/$i
113 done
114
115 ###--------------------------------------------------------------------------
116 ### Some other preliminaries.
117
118 ## Set a per-process memory limit.  It's much less common for a process to
119 ## need a lot of memory for a legitimate reason than for it to be a memory
120 ## leak or some other bug that's going to cause swap death for no good
121 ## reason.
122 ulimit -Sv $(mdw-conf memory-limit 4194303)
123
124 ## Establish a temporary directory.
125 case ${TMPDIR+t} in
126   t) ;;
127   *) if __mdw_programp tmpdir; then eval $(tmpdir -b); fi
128 esac
129 TMP=$TMPDIR; export TMP
130
131 ## Sensible umask if users have their own groups.
132 umask 002
133
134 ###--------------------------------------------------------------------------
135 ### Text editor configuration.
136
137 MDW_EDITOR=ed
138 emacs_startup_args="--no-site-file --mdw-fast-startup -nw"
139 for ed in \
140   "emacs24 $emacs_startup_args" \
141   "emacs23 $emacs_startup_args" \
142   "emacs22 $emacs_startup_args" \
143   "emacs21 $emacs_startup_args" \
144   zile mg \
145   "emacs -nw" \
146   vi pico nano ae
147 do
148   name=${ed%% *}
149   if __mdw_programp "$name"; then MDW_EDITOR=$ed; break; fi
150 done
151 EDITOR=mdw-editor VISUAL=mdw-editor
152 export EDITOR VISUAL MDW_EDITOR
153 unset ed emacs_startup_args
154
155 ###--------------------------------------------------------------------------
156 ### Locale configuration.
157
158 case ${LC_MDWSSHLANG+t},${DISPLAY+t} in
159   t,*)
160     LANG=$LC_MDWSSHLANG
161     ;;
162   ,t)
163     __mdw_setconf LANG x-ctype POSIX
164     ;;
165   *)
166     : LANG=${LC_CTYPE-${LC_ALL-$(mdw-conf console-ctype POSIX)}}
167     case "$TERM,$(tty)" in
168       linux,/dev/tty*)
169         if { vt-is-UTF8 || kbd_mode | grep UTF-8; } >/dev/null 2>&1; then
170           ctype=.UTF-8
171         else
172           ctype=
173         fi
174         LANG=${LANG%.*}$ctype
175         ;;
176     esac
177     ;;
178 esac
179 unset LC_ALL
180 export LANG
181
182 LC_COLLATE=POSIX; export LC_COLLATE
183
184 case ${LANG+t} in
185   t) LC_MDWSSHLANG=$LANG; export LC_MDWSSHLANG ;;
186 esac
187
188 ###--------------------------------------------------------------------------
189 ### Pagers.
190
191 ## Choose a sensible pager.
192 MDW_PAGER=more
193 for pg in less more; do
194   if __mdw_programp "$pg"; then MDW_PAGER=$(command -v "$pg"); break; fi
195 done
196 PAGER=mdw-pager METAMAIL_PAGER=mdw-pager
197 export MDW_PAGER PAGER METAMAIL_PAGER
198 unset pg
199
200 ## Configure `less'.
201 case ${LC_CTYPE-$LANG} in
202   *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;;
203   *) LESSCHARSET=latin1 ;;
204 esac
205 export LESSCHARSET
206 if __mdw_programp global; then
207   LESSGLOBALTAGS=global
208   export LESSGLOBALTAGS
209 fi
210
211 ## Get Debian `groff' to produce control sequences rather than overstriking.
212 GROFF_SGR=t; export GROFF_SGR
213
214 ###--------------------------------------------------------------------------
215 ### Miscellaneous things.
216
217 ## Mail and general identification.
218 __mdw_setconf MAIL mailbox /var/mail/mdw
219 __mdw_setconf EMAIL email mdw@distorted.org.uk
220 NAME="Mark Wooding"; export NAME
221
222 ## News server.
223 __mdw_setconf NNTPSERVER nntp-server
224
225 ## Some programs want to know the hostname.
226 case ${HOST+t} in t) ;; *) HOST=$(hostname); export HOST; esac
227
228 ## HTTP and FTP proxies.
229 http=$(mdw-conf http-proxy none)
230 case "${http_proxy-none},$http" in
231   *,none) ;;
232   none,*://*) http_proxy=$http; export http_proxy ;;
233   none,*) http_proxy=http://$http/; export http_proxy ;;
234 esac
235 https=$(mdw-conf https-proxy none)
236 case "${https_proxy-none},$https,${http_proxy-none}" in
237   *,none,none) ;;
238   none,none,*) https_proxy=$http_proxy; export https_proxy ;;
239   none,*://*,*) https_proxy=$https; export https_proxy ;;
240   none,*,*) https_proxy=http://$https/; export https_proxy ;;
241 esac
242 ftp=$(mdw-conf ftp-proxy none)
243 case "${ftp_proxy-none},$ftp,${http_proxy-none}" in
244   *,none,none) ;;
245   none,none,*) ftp_proxy=$http_proxy; export ftp_proxy ;;
246   none,*://*,*) ftp_proxy=$https; export ftp_proxy ;;
247   none,*,*) ftp_proxy=http://$ftp/; export ftp_proxy ;;
248 esac
249 unset http https ftp
250
251 ## Ncurses programs should use the Unicode box-drawing characters because the
252 ## alternative character set stuff isn't supported well.
253 NCURSES_NO_UTF8_ACS=1; export NCURSES_NO_UTF8_ACS
254
255 ## Shut up Perl's readline machinery.
256 PERL_READLINE_NOWARN=yes; export PERL_READLINE_NOWARN
257
258 ## If we have `distcc' then tell `ccache' to use it.
259 if __mdw_programp distcc; then CCACHE_PREFIX=distcc; export CCACHE_PREFIX; fi
260
261 ## Choose a sensible web browser.  If we have a display, try to pick a
262 ## graphical one.
263 set -- elinks w3m lynx
264 case ${DISPLAY+t} in
265   t) set -- mdw-iceweasel mdw-chrome iceweasel firefox "$@" ;;
266 esac
267 for b in "$@"; do
268   if __mdw_programp $b; then BROWSER=$b; export BROWSER; break; fi
269 done
270 unset b
271
272 ## Acquiring root privileges.  This is mainly the job of `bashrc', but we
273 ## cache the mechanism here.
274 __mdw_setconf __MDW_ROOTLY rootly
275 BECOME="--preserve-environment"; export BECOME
276
277 ## `rsync' configuration.
278 RSYNC_PROTECT_ARGS=1; export RSYNC_PROTECT_ARGS
279
280 ## It's useful to see the little sigils in `ls'.
281 case ${LS_OPTIONS+t} in t) ;; *) LS_OPTIONS="-F"; export LS_OPTIONS; esac
282
283 ## Settings for BBC BASIC listing.
284 export BASCAT="-l +n"
285
286 ## Version control hacking.
287 CVS_RSH=ssh; export CVS_RSH
288 __mdw_setconf CVSROOT cvs-root
289 __mdw_setconf SVNROOT svn-root
290 P4CONFIG=.p4; export P4CONFIG
291
292 ## Help X programs find their resources.
293 XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S"
294 export XUSERFILESEARCHPATH
295
296 ## Make OpenOffice.org do its thing properly.
297 OOO_FORCE_DESKTOP=gnome; export OOO_FORCE_DESKTOP
298
299 ## Hack Qt-ish things to be unstoatly.
300 ##QT_QPA_PLATFORMTHEME=gtk2; export QT_QPA_PLATFORMTHEME
301 QT_AUTO_SCREEN_SCALE_FACTOR=0; export QT_AUTO_SCREEN_SCALE_FACTOR
302
303 ## Use X11 input method (including compose key sequences) everywhere.
304 GTK_IM_MODULE=xim; export GTK_IM_MODULE
305 QT_IM_MODULE=xim; export QT_IM_MODULE
306
307 ## Don't hide scrollbars.
308 GTK_OVERLAY_SCROLLING=0; export GTK_OVERLAY_SCROLLING
309
310 ## Rust Cargo things.
311 CARGO_HOME=$HOME/.cache/cargo; export CARGO_HOME
312
313 ## Configure `ps'.
314 PS_PERSONALITY=gnu; export PS_PERSONALITY
315
316 ## Configure Debian building.
317 DEB_BUILD_OPTIONS="parallel=$(mdw-conf make-parallel 4)"
318 export DEB_BUILD_OPTIONS
319
320 ## Turn on useful colouring.
321 if __mdw_programp dircolors; then
322   eval $(TERM=${TERM-xterm} dircolors -b "$HOME/.dircolors")
323 else
324   unset LS_COLORS
325 fi
326 export GREP_COLORS="mt=01;31:ms=01;31:mc=031;31:fn=36:ln=36:bn=36:se=34"
327 export DIFF_COLORS="hd=1:ln=36:ad=32:de=31"
328
329 ## Turn off angry fruit salad error messages from things.
330 DPKG_COLORS=never; export DPKG_COLORS
331 GCC_COLORS=; export GCC_COLORS
332 CCC_OVERRIDE_OPTIONS="#^-fno-color-diagnostics"; export CCC_OVERRIDE_OPTIONS
333
334 ## Local library directories.
335 __mdw_addto PERLLIB l $HOME/lib/perl; __mdw_export_if_defined PERLLIB
336 __mdw_addto PYTHONPATH l $HOME/lib/python; __mdw_export_if_defined PYTHONPATH
337
338 ## Disable core dumps.
339 ulimit -S -c 0
340
341 ###--------------------------------------------------------------------------
342 ### Authentication and SSH hacking.
343
344 ## Start an authentication agent.  This is unnecessarily fiddly.  If there's
345 ## a Gnome keyring server then we should use that; unfortunately, it may not
346 ## yet have had a chance to populate the environment with its settings, so we
347 ## go off and fetch them.
348 if { { [ "$GNOME_KEYRING_CONTROL" ] &&
349        [ -s "$GNOME_KEYRING_CONTROL" ]; } ||
350      { [ "$DBUS_SESSION_BUS_ADDRESS" ] &&
351        __mdw_programp gnome-keyring-daemon; }; } &&
352    stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null)
353 then
354   eval "$stuff"
355   export SSH_AUTH_SOCK GPG_AGENT_INFO
356 fi
357
358 ## If we still don't have an agent then start one with a stable name.
359 eval $(start-ssh-agent -b)
360
361 ## Decide whether this session should be considered `secure'.  A session is
362 ## secure if it's on a secure TTY, but there are lots of ways of finding out
363 ## which TTYs are secure.
364 if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] ||
365    ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}"
366      { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } ||
367          { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } &&
368        egrep "$devtty" $sectty >/dev/null; } ||
369      { [ -e /etc/default/login ] &&
370        egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } ||
371      case "${tty#/dev/}" in
372        console|systty|tty[0-9]) true ;;
373        *) false ;;
374      esac )
375 then
376   __mdw_sechost=$HOST; export __mdw_sechost
377 fi
378
379 ## Start a passphrase pixie if there is one and it's not already running.
380 if pixie --version >/dev/null 2>&1; then
381   mkdir -p "$HOME/.catacomb"
382   pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie}
383   if [ -S "$pixie" ] && pixie -C help >/dev/null 2>&1; then
384     :
385   else
386     pixie -d 2>>"$HOME/.catacomb/pixie.log"
387     __mdw_started_pixie=yes
388   fi
389 fi
390
391 ###--------------------------------------------------------------------------
392 ### Finishing touches.
393
394 ## For old-fashioned Bourne-ish shells, set up per-shell definitions.
395 ENV=$HOME/.shrc; export ENV
396
397 ## If there's a local hook then run it.
398 if [ -f "$HOME/.profile-local" ]; then . "$HOME/.profile-local"; fi
399
400 ###----- That's all, folks --------------------------------------------------