zjw@shape.mps.ohio-state.edu (Zen Jun Wu) (01/09/91)
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 - <<help! Useage: $name [ [ -d ] dirname ] [ -r [ searchpath ] ] or: $name -h -d Changes working directory to dirname. dirname is a portion of the path of the directory you want to change to. Eg. suppose user has ~/fortran/source/back-d, $name -d -d $name d $name ~/f//c all will bring user to ~/fortran/source/back-d. Default of dirname is the home directory of user. -d may be omitted if dirname is not one of -d, -r, -h. -r Reads the directory tree started from the searchpath, under which dirname is sought. It's necessary only when the directory has been altered since last read. searchpath should be full path, ~/fortran, ~/../user are ok, but ../uer, user/fortran are not. Default of searchpath is the home directory of user. Use setenv NCDDIR searchpath in .login file to change the default. -h Prints this message. help! exit 1 case -d: set dirname=$argv[1] shift breaksw case -r: if ( $#argv >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 |
walt@bcarh133.uucp (Walt Sullivan) (01/09/91)
While I appreciate the effort you've put into ncdcsh, I strongly object to your attempt to change my .login file: > #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 My .login file (which is mine) is MINE! If you want to suggest I add the "alias ncd ...", do so. If I want to add it I will. But, KEEP YOUR HANDS OFF MY .login! Besides, your change will NOT work in my .login - since I usually call x11start (to fire up X-windows) from my .login, I don't get to the end of .login until I'm logging off! Besides, aliases defined in .login will work only in the login shell. In X-windows, all of the shells I use are subshells - my login shell is waiting for me to kill my window manager so it can log me out. I have to define aliases in my .cshrc. -- Walt Sullivan BITNET: walt@BNR.CA (work) UUCP: walt@orbit.amiga.OCUnix.on.ca (home)