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