home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / dirstack.csh / lsdir next >
Encoding:
Text File  |  1987-01-18  |  2.3 KB  |  85 lines

  1. #! /bin/csh -f
  2. #
  3. #    Shell script to load/save current directory stack from/to a file
  4. #
  5. #    Author:        Paul Lew
  6. #    Created at:    02/28/86  12:43
  7. #    Last update:    10/08/86  04:48 PM
  8. #
  9. #    Usage:    source lsdir <CR>    -- must be sourced
  10. #
  11. if ( $?0 ) then
  12.     echo "...You should source this program, not execute it..."
  13.     goto end
  14.     endif
  15. #---------------------------------------------------------------#
  16. #             Variable Declarations            #
  17. #---------------------------------------------------------------#
  18. if ( ! ${?SAVED_WD} ) setenv SAVED_WD ~/saved_wd
  19. unset load_dirs
  20. set fname = ""
  21. echo -n "Enter S/L/D for save/load/directory: "
  22. switch ( "$<" )
  23.     case [lL]:
  24.         set load_dirs
  25.         set opt = 'load'
  26.         breaksw
  27.     case [sS]:
  28.         set opt = 'save'
  29.         breaksw
  30.     case [dD]:
  31.         ls -l ${SAVED_WD}/*.wd | less
  32.         while ( 1 )
  33.             echo -n "File to see (no extension): "
  34.             set fname = "$<"
  35.             if ( ${fname} == "" ) goto end
  36.             cat ${SAVED_WD}/${fname}.wd | shdir
  37.             end
  38.     default:
  39.         goto end
  40.     endsw
  41. #---------------------------------------------------------------#
  42. #    Get filename from terminal and make sure it exists    #
  43. #---------------------------------------------------------------#
  44. while ( "${fname}" == "" )
  45.     echo -n "File to ${opt}: "
  46.     set fname = "$<"
  47.     if ( "${fname}" == "" ) continue
  48.     if ( "${fname:t}" != "${fname}" ) then
  49.         echo -n "No path allowed, "
  50.         set fname = ''
  51.         endif
  52.     set filename = "${SAVED_WD}/${fname}.wd"
  53.     if ( ${?load_dirs} ) then
  54.         if ( ! -e "${filename}" ) then
  55.             echo -n "File [${filename}] does not exist, "
  56.             set fname = ''
  57.             endif
  58.         endif
  59.     end
  60. #---------------------------------------------------------------#
  61. #            Process request                #
  62. #---------------------------------------------------------------#
  63. if ( ${?load_dirs} ) then
  64.     set curdir = `dirs`
  65.     echo "Old directory stack looks like:"
  66.     shdir ${curdir}
  67.     @ dir_count = ${#curdir} - 1
  68.     repeat ${dir_count} popd > /dev/null
  69.     source /usr/local/bin/restdir
  70.     echo "New directory stack looks like:"
  71.     shdir `dirs`
  72. else
  73.     if ( -e ${filename} ) then
  74.         cat ${filename} | shdir
  75.         echo -n "Old file listed above, override? [y/n]: "
  76.         if ( "$<" != "y" ) goto end
  77.         endif
  78.     dirs > ${filename}
  79.     endif
  80. #---------------------------------------------------------------#
  81. #        Clean up and exit here...            #
  82. #---------------------------------------------------------------#
  83. end:
  84.     unset filename fname load_dirs dir_count curdir
  85.