Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!news From: zjw@shape.mps.ohio-state.edu (Zen Jun Wu) Newsgroups: comp.unix.shell Subject: UNIX C SHELL'S VERSION OF NORTON'S CD Message-ID: <1991Jan8.230024.15851@zaphod.mps.ohio-state.edu> Date: 8 Jan 91 23:00:24 GMT References: cd,csh Sender: news@zaphod.mps.ohio-state.edu Organization: Department of Mathematics, The Ohio State University Lines: 178 Nntp-Posting-Host: shape.mps.ohio-state.edu The following is UNIX C SHELL's VERSION OF NORTON's CD, which is well known in the MS-DOS world. But this one is even more powerful. Eg. suppose user has ~/fortran/source/back-d, ncd -d -d ncd d ncd /-d ncd s/b ncd f/o/c ncd ~//r/k all will bring user to ~/fortran/source/back-d. Save this news as ncdcsh and cut header. Run it by using csh -f ncdcsh logout then login, type ncd -h to see the help message. Any improvement or enhancement is welcome and I gladly like to know about it. ______________________________________________________________________________ Zhenjun Wu | The more you learn, | Internet: zjw@shape.mps.ohio | Dept. of Math. | the more you gain, | -state.edu | The Ohio State Univ.| the more you achieve!|_________________________________| ############################################################################## -----------Cut here and save the following as ncdcsh ------------------------ #add alias ncd ... in .login file if there isn't. if ( ! `egrep -c '(alias) (ncd)' ${HOME}/.login `) \ echo 'alias ncd "${HOME}/.ncdcsh \!* && cd `cat ${HOME}/.ncddir ` " ' >> \ ${HOME}/.login #creat .ncdcsh file cat - >! ${HOME}/.ncdcsh <<'NCDFILE' #!/bin/csh -f ####################################################################### # # # UNIX C SHELL VERSION OF NORTORN'S CD, V1.0 1990 # # # # CHANGE WORKING DIRECTORY EASILY BY USING ONE OR MORE # # LETTERS OF THE PATH. # # # # WRITTEN BY ZHENJUN WU, # # THE DEPARTMENT OF MATHEMATICS, # # THE OHIO STATE UNIVERSITY # # INTERNET: zjw@shape.mps.ohio-state.edu # # # ####################################################################### #command name set name=ncd #the file to store the dirctory set ncde=${home}/.${name}dir # if no argument, use cd if ( ! $#argv ) then cd exit 1 endif # the file to store the directory tree set namerc = "${HOME}/.${name}rc" # if env variable NCDDIR is not set, we use ${HOME} if ( ! ${?NCDDIR} ) setenv NCDDIR ${HOME} # get arguments while ( $#argv > 0 ) set par = $argv[1] shift switch ($par) case -h: cat - <0 ) then if ( -d $argv[1] ) then setenv NCDDIR $argv[1] else echo $argv[1] is not a directory exit 1 endif shift endif du $NCDDIR |& grep -v "Permission"| cut -f 2 >! "$namerc" breaksw default: set dirname=$par endsw end # read the diirectory tree if ( !(-f $namerc) ) then du $NCDDIR |& grep -v "Permission"| cut -f 2 >! "$namerc" endif if ( ! ${?dirname} ) exit 2 # select dir. roughly first set eg=`echo $dirname |tr '/' ' ' ` set pdir=` egrep -e "$eg[$#eg]" $namerc |tr '\12' ' ' ` set noglob set dirn=`echo "$dirname" |sed -e 's/\// .*/g' ` unset noglob # find dir. user needs foreach i ( `echo $pdir` ) set j=` echo $i |tr '/' ' ' ` @ nj=$#j @ n=$#dirn if ( $nj >= $n ) then unset nodir while ( $n ) if ( ! `echo $j[$nj] | grep -c -e "$dirn[$n]" ` ) then set nodir break endif @ n-- @ nj-- end if ( ! ${?nodir} ) then if ( ${?predir} ) then echo -n "cd $predir (y/n)?" set st=$< if ( "@$st" == "@y" || "@$st" == "@Y" ) then echo $predir >! $ncde exit 0 else set predir=$i endif else set predir=$i endif endif endif end if ( ${?predir} ) then echo $predir >! $ncde exit 0 else echo Directory $dirn not found echo Use $name -h to get help exit 1 endif 'NCDFILE' chmod 700 ${HOME}/.ncdcsh echo ncd is installed. echo logout and loging in, type echo ncd -h echo to see the help message. -- ______________________________________________________________________________ Zhenjun Wu | The more you learn, | Internet: zjw@shape.mps.ohio | Dept. of Math. | the more you gain, | -state.edu |