CSH script help needed

Spencer W. Thomas thomas at utah-gr.UUCP
Tue Jan 10 12:47:17 AEST 1984


1. The "plugh" command you show is pretty well covered by the pushd
   command in 4bsd and later c-shells.  If you are still in v7-land,
   the following should do it:

alias plugh 'if ( "\!*" == "" ) cd $prevdir;'\
	'if ( "\!*" != "" ) cd \!*;'\
	'set prevdir = $cwd'

alias cd 'cd \!*; set cwd=`pwd`'

2. To get your current directory in the prompt, the following aliases
will do it (assuming 4bsd csh, which automatically sets the cwd variable):

alias	cd	'cd \!*; setprompt'
alias	pd	'pushd \!*; setprompt'
alias	popd	'popd \!*; setprompt'
set baseprompt = bbna
alias	setprompt 'set prompt="$baseprompt $cwd >"'

A slightly fancier version takes into account your favorite csh
variables to abbreviate the directory name:
alias	sortset	source ~/bin/sortset
set	baseprompt = "$prompt:q"
alias	setprompt 'set prompt="["`echo $cwd | sed -f ~/.set`"]$baseprompt:q"'

This gives a prompt like
[$foo/bar] utah-gr>

The sortset script is given below.  It contains as special cases a few
variables that I do NOT want to see in my prompt.

set | awk '/^ds/ { next; }\
/^old/ { next; }\
/^cwd/ { next; }\
/	\// { if (NF == 2) print length($2), $0; }\
{ next; }' | sort -rn |\
	awk '{ if ($3 != "'${HOME}'") printf "s;%s;$%s;\n", $3, $2; }\
END { print "s;'${HOME}';~;"; }' >~/.set

=Spencer



More information about the Comp.unix.wizards mailing list