New uses for csh

Mats Wichmann mats at dual.UUCP
Tue Jun 26 08:23:41 AEST 1984


RE: Gordon's neato implementation of pushd/popd for csh's that don't have
them....

>> [in my .cshrc]:
>>	alias	popd	'set argv = (\!*) ; source ~/csh/popd'
>>	alias	pushd	'set argv = (\!*) ; source ~/csh/pushd'

>> [~/csh/popd]:
>> 	if (! $?_dirstack || $#_dirstack < 1) then
>> 		echo "popd: Directory stack empty."
>> 	else
>> 		chdir $_dirstack[1]
>> 		echo $_dirstack
>> 		shift _dirstack
>> 	endif

>> [~/csh/pushd]:
>> 	if ($#argv != 1) then
>> 		echo "pushd: Arg count."
>> 	else
>> 		if (! $?_dirstack) set $_dirstack = ()
>> 		set _dirstack = (`pwd` $_dirstack)
>>  		chdir $argv
>> 		echo $argv $_dirstack
>> 	endif

I am not trying to criticise the intent of the article, which was to show
a method for fudging more complex alias commands. However, the specific
example used can be done more quickly, although it is not as complete an
emulation...

Try this (all in your .cshrc)

	if (! $?_d ) set _d = ()
	alias pushd	set _d = \(\`pwd\` \$_d\) \; cd \!\*
	alias popd	cd \$_d\[1\] \; echo \$_d\[1\] : \; shift _d

Avoids opening an extra file each time for the source, although it has a
less elegant error recovery...I use it quite a bit when jumping around
the system. 

	Mats



More information about the Comp.unix mailing list