Subject: Re: configuration file tricks of the masters
To: VaX#n8 <>
From: Warner Losh <>
List: netbsd-users
Date: 08/05/1997 11:37:03
In message <> VaX#n8 writes:
: I am interested in:
:  o clever hacks
:  o generating multiple customized copies from one master
:  o mixing automatically-generated and user-generated data
:  o portable shell coding techniques
: Comments and submissions welcome.

I'm not sure if this is the right forum to reply, but here are a
couple of the ones that I use.

I have a list of dirs that I want for my path.  I don't want all of
them in my path for a variety of reasons.  So I use the following csh
code to deal.  It also shows how to have inline functions in tcsh.
Kinda gross, but it does seem to do the job.

set host=`uname -n`
set __uname_s=`uname -s`
set __uname_r=`uname -r`
set os=`echo "$__uname_s-$__uname_r" | sed -e 's/\..*$//'`

# This shows how to use aliases as inline functions in csh This really
# should be expanded inline in the following code, but I'm leaving it
# here so that I can know how to do this in the future.  __maybe_add
# takes two parameters: The env var to update, and the directory to
# prepend if it isn't already in the path list.  This is the closest
# csh comes to functions...
alias __maybe_add 'if ((:${\!:1}: !~ *:\!:2\:*) && -d \!:2) set \!:1=${\!:1}\:\!:2'

# OK, let's try to be nice to the network and only do the rehashing
# stuff once.  Seems to be a tiny bit faster, but not by much in the
# default case, and just as slow otherwise.  We'll see if this is any
# better than alternatives or not.  It would appear that much of the
# slowness is due to other factors (mostly the .subscriptions file that
# is a little silly about some things).
# Also make sure that /usr/ucb is toward the front of the list.
set  __P=/usr/ucb:`echo $PATH | sed 's=/usr/ucb==;s/::/:/;s/^://;s/:$//'`
foreach i (~/bin ~/bin/$host ~/bin/$os \
		~imp/bin ~imp/bin/$host ~imp/bin/$os \
		/usr/etc /usr/local/bin /usr/local/mh/bin \
		/usr/local/bin/mh /usr/bin/X11 /usr/X11R6/bin \
		/opt/SUNWspro/bin \
		/usr/openwin/bin /usr/local/bin/X11 /usr/local/X11R6/bin \
		/usr/ucb /usr/bin /bin /usr/sbin /sbin \
		/usr/local/sbin /usr/ccs/bin .)
	__maybe_add __P $i
setenv PATH $__P
unset __P

unset __uname_s __uname_r
unalias __maybe_add