### -*-sh-*- ### ### Session startup things. ## The shell-specific hook will run us if it thinks we haven't been run ## before. We should therefore let it know. __mdw_profile=t; export __mdw_profile ###-------------------------------------------------------------------------- ### Utility functions. ## __mdw_addto VAR DIR PATH ... ## ## VAR is the name of a PATH-like environment variable (i.e., one which ## contains a sequence of pathnames separated by colons). DIR is either `l' ## or `r'. The PATHs are pathnames. Those PATHs which correspond to ## existing directories but which aren't currently named in the variable are ## added to the left or right (depending on DIR) of VAR. The relative order ## of PATHs added in the same invokation is the same as the order they ## appeared in PATHs: the DIR argument only affects which end of the VAR they ## get added to. __mdw_addto () { local var=$1 val dir=$2 new="" change=nil eval val=\$$var shift 2 for i in "$@"; do case "$new:" in *:$i:*) continue;; esac if ! [ -d $i ]; then continue; fi case "$val" in "") val=$i change=t; continue ;; $i) continue ;; *:$i:*) val=${val%%:$i:*}:${val#*:$i:} ;; $i:*) val=${val#$i:} ;; *:$i) val=${val%:$i} ;; esac new=$new:$i change=t done case $dir in l) val=${new#:}:$val ;; r) val=$val$new ;; esac case $change in t) eval $var=\$val ;; esac } ## __mdw_programp NAME ## ## Does NAME exist as an executable program? __mdw_programp () { type >/dev/null 2>&1 "$1"; } ## __mdw_setconf VAR CONF [DEFAULT] ## ## If CONF is defined in `~/.mdw.conf' then set VAR to its value; otherwise, ## set VAR to DEFAULT, if given; otherwise, do nothing at all. __mdw_setconf () { local var=$1 conf=$2 val; shift 2 if val=$(mdw-conf 2>/dev/null "$conf" "$@"); then eval "$var=\$val; export $var" fi } ###-------------------------------------------------------------------------- ### Other preliminaries. ## Work out my home directory, resolving symbolic links. HOME=$(cd "$HOME"; pwd -P) case ${SCHROOT_SESSION_ID+t} in t) ;; *) cd "$HOME" ;; esac ## CDE's session structure is demented and doesn't leave us with a proper ## logout hook, so synthesize one here. case ${DT+t} in t) trap "source $HOME/.shell-logout" EXIT; esac ###-------------------------------------------------------------------------- ### Set some basic paths. ## The main path. export PATH __mdw_addto PATH l \ "$HOME"/bin \ /usr/local/bin /usr/local/sbin /usr/local/games \ /usr/bin /usr/sbin /usr/games \ /usr/X11R6/bin /usr/local/X11R6/bin \ /bin /sbin \ /opt/nfast/bin /opt/nfast/sbin ## If we have Plan 9 from User Space, then add that in. for i in /opt/plan9 /usr/local/plan9; do if [ -d $i ]; then PLAN9=$i; export PLAN9 __mdw_addto PATH r $i/bin break fi done ## Check for some standard path hacks. for i in ccache; do __mdw_addto PATH l "$HOME"/bin/hacks/$i done ###-------------------------------------------------------------------------- ### Some other preliminaries. ## Establish a temporary directory. case ${TMPDIR+t} in t) ;; *) if __mdw_programp tmpdir; then eval $(tmpdir -b); fi esac TMP=$TMPDIR; export TMP ## Sensible umask if users have their own groups. umask 002 ###-------------------------------------------------------------------------- ### Text editor configuration. MDW_EDITOR=ed emacs_startup_args="--no-site-file --mdw-fast-startup -nw" for ed in \ "emacs24 $emacs_startup_args" \ "emacs23 $emacs_startup_args" \ "emacs22 $emacs_startup_args" \ "emacs21 $emacs_startup_args" \ zile mg \ "emacs -nw" \ vi pico nano ae do name=${ed%% *} if __mdw_programp "$name"; then MDW_EDITOR=$ed; break; fi done EDITOR=mdw-editor VISUAL=mdw-editor export EDITOR VISUAL MDW_EDITOR unset ed emacs_startup_args ###-------------------------------------------------------------------------- ### Locale configuration. case ${LC_MDWSSHLANG+t},${DISPLAY+t} in t,*) LANG=$LC_MDWSSHLANG ;; ,t) __mdw_setconf LANG x-ctype POSIX ;; *) : LANG=${LC_CTYPE-${LC_ALL-$(mdw-conf console-ctype POSIX)}} case "$TERM,$(tty)" in linux,/dev/tty*) if { vt-is-UTF8 || kbd_mode | grep UTF-8; } >/dev/null 2>&1; then ctype=.UTF-8 else ctype= fi LANG=${LANG%.*}$ctype ;; esac ;; esac unset LC_ALL export LANG LC_COLLATE=POSIX; export LC_COLLATE case ${LANG+t} in t) LC_MDWSSHLANG=$LANG; export LC_MDWSSHLANG ;; esac ###-------------------------------------------------------------------------- ### Pagers. ## Choose a sensible pager. MDW_PAGER=more for pg in less more; do if __mdw_programp "$pg"; then MDW_PAGER=$(command -v "$pg"); break; fi done PAGER=mdw-pager METAMAIL_PAGER=mdw-pager export MDW_PAGER PAGER METAMAIL_PAGER unset pg ## Configure `less'. case ${LC_CTYPE-$LANG} in *utf8 | *utf-8 | *UTF8 | *UTF-8) LESSCHARSET=utf-8 ;; *) LESSCHARSET=latin1 ;; esac export LESSCHARSET if __mdw_programp global; then LESSGLOBALTAGS=global export LESSGLOBALTAGS fi ###-------------------------------------------------------------------------- ### Miscellaneous things. ## Mail and general identification. __mdw_setconf MAIL mailbox /var/mail/mdw __mdw_setconf EMAIL email mdw@distorted.org.uk NAME="Mark Wooding"; export NAME ## News server. __mdw_setconf NNTPSERVER nntp-server ## Some programs want to know the hostname. case ${HOST+t} in t) ;; *) HOST=$(hostname); export HOST; esac ## HTTP and FTP proxies. http=$(mdw-conf http-proxy none) case "${http_proxy-none},$http" in *,none) ;; none,*) http_proxy=http://$http/; export http_proxy ;; esac https=$(mdw-conf https-proxy none) case "${https_proxy-none},$https,${http_proxy-none}" in *,none,none) ;; none,none,*) https_proxy=$http_proxy; export https_proxy ;; none,*,*) https_proxy=http://$https/; export ftp_proxy ;; esac ftp=$(mdw-conf ftp-proxy none) case "${ftp_proxy-none},$ftp,${http_proxy-none}" in *,none,none) ;; none,none,*) ftp_proxy=$http_proxy; export ftp_proxy ;; none,*,*) ftp_proxy=http://$ftp/; export ftp_proxy ;; esac unset http https ftp ## Ncurses programs should use the Unicode box-drawing characters because the ## alternative character set stuff isn't supported well. NCURSES_NO_UTF8_ACS=1; export NCURSES_NO_UTF8_ACS ## Shut up Perl's readline machinery. PERL_READLINE_NOWARN=yes; export PERL_READLINE_NOWARN ## If we have `distcc' then tell `ccache' to use it. if __mdw_programp distcc; then CCACHE_PREFIX=distcc; export CCACHE_PREFIX; fi ## Choose a sensible web browser. If we have a display, try to pick a ## graphical one. set -- elinks w3m lynx case ${DISPLAY+t} in t) set -- mdw-iceweasel mdw-chrome iceweasel firefox "$@" ;; esac for b in "$@"; do if __mdw_programp $b; then BROWSER=$b; export BROWSER; break; fi done unset b ## Acquiring root privileges. This is mainly the job of `bashrc', but we ## cache the mechanism here. __mdw_setconf __MDW_ROOTLY rootly BECOME="--preserve-environment"; export BECOME ## It's useful to see the little sigils in `ls'. case ${LS_OPTIONS+t} in t) ;; *) LS_OPTIONS="-F"; export LS_OPTIONS; esac ## Settings for BBC BASIC listing. export BASCAT="-l +n" ## Version control hacking. CVS_RSH=ssh; export CVS_RSH __mdw_setconf CVSROOT cvs-root __mdw_setconf SVNROOT svn-root P4CONFIG=.p4; export P4CONFIG ## Help X programs find their resources. XUSERFILESEARCHPATH="$HOME/.Xapps/%N:/usr/lib/X11/%T/%N%S" export XUSERFILESEARCHPATH ## Make OpenOffice.org do its thing properly. OOO_FORCE_DESKTOP=gnome; export OOO_FORCE_DESKTOP ## Hack Qt-ish things to be unstoatly. QT_STYLE_OVERRIDE=gtk2; export QT_STYLE_OVERRIDE ## Use X11 input method (including compose key sequences) everywhere. GTK_IM_MODULE=xim; export GTK_IM_MODULE QT_IM_MODULE=xim; export QT_IM_MODULE ## Configure `ps'. PS_PERSONALITY=gnu; export PS_PERSONALITY ## Disable core dumps. ulimit -S -c 0 ###-------------------------------------------------------------------------- ### Authentication and SSH hacking. ## Start an authentication agent. This is unnecessarily fiddly. If there's ## a Gnome keyring server then we should use that; unfortunately, it may not ## yet have had a chance to populate the environment with its settings, so we ## go off and fetch them. if { { [ "$GNOME_KEYRING_CONTROL" ] && [ -s "$GNOME_KEYRING_CONTROL" ]; } || { [ "$DBUS_SESSION_BUS_ADDRESS" ] && __mdw_programp gnome-keyring-daemon; }; } && stuff=$(gnome-keyring-daemon -s -c gpg 2>/dev/null) then eval "$stuff" export SSH_AUTH_SOCK GPG_AGENT_INFO fi ## If we still don't have an agent then start one with a stable name. eval $(start-ssh-agent -b) ## Decide whether this session should be considered `secure'. A session is ## secure if it's on a secure TTY, but there are lots of ways of finding out ## which TTYs are secure. if [ -z "$__mdw_bashrc" ] && [ "$__mdw_force_secure_session" = "yes" ] || ( tty="`tty`" devtty="(/dev/)?${tty#/dev/}" { { { [ -e /etc/securetty ] && sectty=/etc/securetty; } || { [ -e /etc/securettys ] && sectty=/etc/securettys; }; } && egrep "$devtty" $sectty >/dev/null; } || { [ -e /etc/default/login ] && egrep "^CONSOLE=$devtty" /etc/default/login >/dev/null; } || case "${tty#/dev/}" in console|systty|tty[0-9]) true ;; *) false ;; esac ) then __mdw_sechost=$HOST; export __mdw_sechost fi ## Start a passphrase pixie if there is one and it's not already running. if pixie --version >/dev/null 2>&1; then mkdir -p "$HOME/.catacomb" pixie=${CATACOMB_PIXIE-$HOME/.catacomb/pixie} if [ -S "$pixie" ] && pixie -C help >/dev/null 2>&1; then : else pixie -d 2>>"$HOME/.catacomb/pixie.log" __mdw_started_pixie=yes fi fi ###-------------------------------------------------------------------------- ### Finishing touches. ## For old-fashioned Bourne-ish shells, set up per-shell definitions. ENV=$HOME/.shrc; export ENV ## If there's a local hook then run it. if [ -f "$HOME/.profile-local" ]; then . "$HOME/.profile-local"; fi ###----- That's all, folks --------------------------------------------------