chiark / gitweb /
dot/bash_profile, setup: Emacs 24 seems cromulent.
[profile] / dot / bash_profile
CommitLineData
ca7933c9 1### -*-bash-*-
59c9c0e4
MW
2###
3### Bash startup things
f617db13 4
8523d789
MW
5## The `.bashrc' hook will run us if it thinks we haven't been run before.
6## We should therefore let it know.
f617db13
MW
7export __mdw_profile=done
8
59c9c0e4
MW
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.
f617db13 22__mdw_addto () {
85d3810b 23 local var=$1 val dir=$2 new="" change=nil
f617db13
MW
24 eval "val=\$$var"
25 shift 2
26 for i in "$@"; do
27 case "$new:" in *:$i:*) continue;; esac
28 [ -d $i ] || continue
29 case "X$val" in
59c9c0e4
MW
30 X) val=$i change=t continue ;;
31 X$i) continue ;;
32 X*:$i:*) val=`echo $val | sed -e "s=:$i:=:="` ;;
33 X$i:*) val=${val#$i:} ;;
34 X*:$i) val=${val%:$i} ;;
f617db13 35 esac
85d3810b 36 new=$new:$i change=t
f617db13
MW
37 done
38 case $dir in
59c9c0e4
MW
39 l) val=${new#:}:$val ;;
40 r) val=$val$new ;;
f617db13 41 esac
584e04e1 42 case $change in t) export $var="$val" ;; esac
f617db13
MW
43}
44
59c9c0e4
MW
45## __mdw_programp NAME
46##
47## Does NAME exist as an executable program?
48__mdw_programp () { type -t >/dev/null "$1"; }
49
50###--------------------------------------------------------------------------
51### Other preliminaries.
52
53## Work out my home directory.
54##
55## This horrible trick resolves symbolic links. It enables resolving links,
56## changes directory and displays the name of the directory in a subshell to
57## avoid changing the current state.
58HOME=`(set -P; cd $HOME; pwd)`
3afe7de5 59[ -n "$SCHROOT_SESSION_ID" ] || cd $HOME
59c9c0e4 60
59c9c0e4
MW
61## CDE's session structure is demented and doesn't leave us with a proper
62## logout hook, so synthesize one here.
63[ -n "$DT" ] && trap "source $HOME/.bash_logout" EXIT
64
65###--------------------------------------------------------------------------
66### Set some basic paths.
f617db13 67
59c9c0e4 68## The main path.
f617db13 69__mdw_addto PATH l \
f141fe0f 70 $HOME/bin \
d0cefd73 71 {/usr{/local,}{,/X11R6},}{/bin,/sbin,/games} \
b187640a 72 /opt/nfast{,/gcc}{/bin,/sbin} \
f617db13 73 $HOME/src/ncipher/scripts
59c9c0e4
MW
74
75## If we have Plan 9 from User Space, then add that in.
f141fe0f
MW
76if [ -d /usr/local/plan9 ]; then
77 export PLAN9=/usr/local/plan9
78 __mdw_addto PATH r \
79 $PLAN9/bin
80fi
f617db13 81
59c9c0e4
MW
82## Search for `info' documents.
83__mdw_addto INFOPATH r \
84 $HOME/info \
85 /usr/info /usr/share/info \
86 /usr/local/info /usr/local/share/info \
87 /usr/local/share/info/its
2041672d 88
59c9c0e4
MW
89## Script libraries.
90__mdw_addto PERLLIB r $HOME/lib/perl
91__mdw_addto PYTHONPATH r $HOME/lib/python
f617db13 92
59c9c0e4
MW
93###--------------------------------------------------------------------------
94### Various other kinds of configuration.
f617db13 95
7738df0b
MW
96## Establish a temporary directory.
97[ "$TMPDIR" ] || eval `tmpdir -b`
98export TMP=$TMPDIR
99
59c9c0e4
MW
100## Sensible umask if users have their own groups.
101umask 002
f617db13 102
59c9c0e4 103## Mail and general identification.
b056f5c4 104export MAIL=`mdw-conf mailbox`
f617db13 105export NAME="Mark Wooding"
b056f5c4 106export EMAIL=`mdw-conf email`
f617db13
MW
107export QMAILINJECT=c
108
59c9c0e4
MW
109## Some programs want to know the hostname.
110[ -z "$HOST" ] && export HOST=`hostname`
f374674c 111
59c9c0e4 112## Text editor configuration.
e04c4857 113export MDW_EDITOR=ed
f3f622e3
MW
114emacs_startup_args="--no-site-file --mdw-fast-startup -nw"
115for ed in \
f7876fa9
MW
116 "emacs23 $emacs_startup_args" \
117 "emacs24 $emacs_startup_args" \
f3f622e3
MW
118 "emacs22 $emacs_startup_args" \
119 "emacs21 $emacs_startup_args" \
b0d8acbe 120 zile mg \
f3f622e3
MW
121 "emacs -nw" \
122 vi pico nano ae; do
97b82392 123 name=`echo $ed | sed 's/ .*$//'`
2041672d 124 if __mdw_programp "$name"; then
e04c4857 125 MDW_EDITOR=$ed
97b82392
MW
126 break
127 fi
128done
e04c4857 129export EDITOR=mdw-editor VISUAL=mdw-editor
97b82392 130
59c9c0e4
MW
131## Determine the locale settings. Really don't set LC_COLLATE because it
132## messes with the order of files in `ls' listings and similar.
703b345d
MW
133if [ "$DISPLAY" != "" ]; then
134 LANG=`mdw-conf x-ctype`
bc30f5c4 135else
703b345d 136 : ${LANG=${LC_CTYPE-${LC_ALL-`mdw-conf console-ctype`}}}
c537b3bf
MW
137 case "$TERM,`tty`" in
138 linux,/dev/tty*)
4abf3071
MW
139 if { vt-is-UTF8 ||
140 kbd_mode | grep UTF-8; } >/dev/null 2>&1; then
703b345d
MW
141 ctype=.utf8
142 else
143 ctype=
144 fi
145 LANG=${LANG%.*}$ctype
146 ;;
147 esac
bc30f5c4 148fi
703b345d
MW
149unset LC_ALL
150export LC_COLLATE=POSIX LANG
bc5bd6eb 151
59c9c0e4 152## Pager configuration.
b20bfd83 153export MDW_PAGER=`type -p less` PAGER=mdw-pager METAMAIL_PAGER=mdw-pager
c363cf92 154export LESS="-iqgRh1j.3FSX"
f617db13 155export LESSOPEN="|lesspipe.sh %s"
e1375853 156case "${LC_CTYPE-$LANG}" in
c66a7e44 157 *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;;
6121c48e
MW
158 *) LESSCHARSET=latin1 ;;
159esac
160export LESSCHARSET
d03de69c 161__mdw_programp global && export LESSGLOBALTAGS=global
93ba996d 162
59c9c0e4 163## HTTP and FTP proxies.
93ba996d
MW
164http=`mdw-conf http-proxy none`
165case "${http_proxy-none},$http" in
166 *,none) ;;
4b1d5c25 167 none,*) export http_proxy=http://$http/ ;;
93ba996d
MW
168esac
169ftp=`mdw-conf ftp-proxy none`
170case "${ftp_proxy-none},$ftp,${http_proxy-none}" in
171 *,none,none) ;;
172 none,none,*) export ftp_proxy=$http_proxy ;;
4b1d5c25 173 none,*,*) export ftp_proxy=http://$ftp/ ;;
93ba996d 174esac
f617db13 175
59c9c0e4
MW
176## Ncurses programs should use the Unicode box-drawing characters because the
177## alternative character set stuff isn't supported well.
178export NCURSES_NO_UTF8_ACS=1
179
180## Shut up Perl's readline machinery.
181export PERL_READLINE_NOWARN=yes
182
183## If we have `distcc' then tell `ccache' to use it.
184__mdw_programp distcc && export CCACHE_PREFIX=distcc
185
69186ec2
MW
186## Choose a sensible web browser. If we have a display, try to pick a
187## graphical one.
188browsers="elinks w3m lynx"
189case "${DISPLAY+t}" in
e2bc0218 190 t) browsers="mdw-iceweasel mdw-chrome iceweasel firefox $browsers" ;;
69186ec2
MW
191esac
192for i in $browsers; do
193 if __mdw_programp $i; then
194 export BROWSER=$i
195 break
196 fi
197done
198unset browsers
199
59c9c0e4
MW
200## Acquiring root privileges. This is mainly the job of `bashrc', but we
201## cache the mechanism here.
202export __MDW_ROOTLY=`mdw-conf rootly`
203export BECOME="--preserve-environment"
204
205## It's useful to see the little sigils in `ls'.
206[ -z "$LS_OPTIONS" ] && export LS_OPTIONS="-F"
207
208## Settings for BBC BASIC listing.
209export BASCAT="-l +n"
210
211## Version control hacking.
212export CVS_RSH=ssh
213export CVSROOT=`mdw-conf cvs-root`
214export SVNROOT=`mdw-conf svn-root`
215export P4CONFIG=.p4
216
217## News server.
218[ -z "$NNTPSERVER" ] && export NNTPSERVER=`mdw-conf nntp-server`
219
220## Help X programs find their resources.
f617db13
MW
221export XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S"
222
59c9c0e4 223## Make OpenOffice.org do its thing properly.
a5abc1d2
MW
224export OOO_FORCE_DESKTOP=gnome
225
59c9c0e4 226## Configure `ps'.
f617db13
MW
227export PS_PERSONALITY=gnu
228
59c9c0e4 229## Disable core dumps.
f617db13
MW
230ulimit -S -c 0
231
59c9c0e4
MW
232###--------------------------------------------------------------------------
233### Authentication and SSH hacking.
f617db13 234
59c9c0e4
MW
235## Start an authentication agent. This is unnecessarily fiddly. If there's
236## a Gnome keyring server then we should use that; unfortunately, it may not
237## yet have had a chance to populate the environment with its settings, so we
238## go off and fetch them.
f589321e
MW
239if { { [ "$GNOME_KEYRING_CONTROL" ] &&
240 [ -s "$GNOME_KEYRING_CONTROL" ]; } ||
241 { [ "$DBUS_SESSION_BUS_ADDRESS" ] &&
242 dbus-send --session --print-reply --dest=org.freedesktop.DBus \
243 / org.freedesktop.DBus.GetNameOwner string:org.gnome.keyring \
244 >/dev/null 2>/dev/null; }; } &&
245 stuff=$(gnome-keyring-daemon -s -c ssh 2>/dev/null)
b8e1fad6
MW
246then
247 eval "$stuff"
f589321e 248 export SSH_AUTH_SOCK
1ee51934
MW
249fi
250
59c9c0e4 251## If we still don't have an agent then start one with a stable name.
f617db13
MW
252eval `start-ssh-agent -b`
253
59c9c0e4
MW
254## Decide whether this session should be considered `secure'. A session is
255## secure if it's on a secure TTY, but there are lots of ways of finding out
256## which TTYs are secure.
f617db13
MW
257if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] ||
258 ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}"
259 { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } ||
852cd5fb 260 { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } &&
f617db13
MW
261 egrep "$devtty" $sectty >/dev/null; } ||
262 { [ -e /etc/default/login ] &&
263 egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } ||
264 case "${tty#/dev/}" in
265 console|systty|tty[0-9]) true ;;
266 *) false ;;
267 esac )
268then
269 export __mdw_sechost="`hostname`"
270fi
271
59c9c0e4 272## Start a passphrase pixie if there is one and it's not already running.
f617db13 273if pixie --version >/dev/null 2>&1; then
365662c8 274 mkdir -p $HOME/.catacomb
f617db13
MW
275 pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie}
276 if [ -S "$pixie" ] && pixie -C help >/dev/null 2>/dev/null; then
277 :
278 else
279 pixie -d 2>>$HOME/.catacomb/pixie.log
280 __mdw_started_pixie=yes
281 fi
282fi
283
59c9c0e4
MW
284###--------------------------------------------------------------------------
285### Finishing touches.
286
287## If there's a local hook then run it.
68aea1d9
MW
288[ -f "$HOME/.profile-local" ] && . "$HOME/.profile-local"
289
59c9c0e4
MW
290## If we haven't run the `.bashrc' yet, and this shell is interactive, then
291## run it now.
f617db13
MW
292[ -z "$__mdw_bashrc" ] && [ -t 0 ] && \
293 [ -r $HOME/.bashrc ] && . $HOME/.bashrc
59c9c0e4
MW
294
295###----- That's all, folks --------------------------------------------------