home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume7 / dirstack.csh / useshdir < prev   
Text File  |  1987-01-18  |  4KB  |  118 lines

  1. #! /bin/csh -f
  2. #
  3. #-    useshdir - Update .login, .logout, and .cshrc to install shdir
  4. #-
  5. #-    This program will modify your .cshrc, .login, and .logout files
  6. #-    so that: (1) proper aliases will be defined. (2) directory stack
  7. #-    will be saved on logout and restored on login.
  8. #-
  9. #    Author:        Paul Lew, General Systems Group, Salem, NH
  10. #    Created at:    10/08/86  12:23 PM
  11. #    Last update:    10/14/86  02:28 PM
  12. #
  13. #-    Usage:    useshdir dirname <CR>
  14. #-
  15. #-    where: dirname is the directory where the shdir stored.
  16. #
  17. set tmpfile = "/tmp/shdir$$.setup"
  18. #---------------------------------------------------------------#
  19. #       Find shdir directory if not specified        #
  20. #---------------------------------------------------------------#
  21. set dir = "$1"
  22. if ( "${dir}" == "" ) set dir = '/usr/local/bin'
  23. while (1)
  24.     if ( -e "${dir}/shdir" ) break
  25.     echo -n "Which directory did the shdir stored? "
  26.     set dir = "$<"
  27.     end
  28. #---------------------------------------------------------------#
  29. #        Get Box style choice from the user            #
  30. #---------------------------------------------------------------#
  31. cat << cat_eof
  32.  
  33. shdir can display the box in 3 styles (only if your terminal can
  34. support the selected feature, i.e., proper entries in termcap
  35. database):
  36.  
  37.     <1> special graphical character set for lines (default)
  38.     <2> reverse video blanks
  39.     <3> hightlighted blanks
  40.  
  41. cat_eof
  42. echo -n "Please make a choice: [1-3]: "
  43. switch ( "$<" )
  44.     case 2:
  45.         set shdir = (shdir -br)
  46.         breaksw
  47.     case 3:
  48.         set shdir = (shdir -bh)
  49.         breaksw
  50.     case 1:
  51.     default:
  52.         set shdir = (shdir)
  53.     endsw
  54. #---------------------------------------------------------------#
  55. #        Add aliases to .cshrc file            #
  56. #---------------------------------------------------------------#
  57. set msg = "Directory stack operation aliases"
  58. @ added = 0
  59. if ( -e ~/.cshrc ) @ added = `grep "${msg}" ~/.cshrc | wc -l`
  60. if ( ${added} == 0 ) then
  61.     cat > ${tmpfile} << cat_eof
  62. #
  63. # ${msg}  (Added: `date`)
  64. #
  65. alias    lsdir    'source ${dir}/lsdir'
  66. alias    po    'popd +\!* > /dev/null; '"${shdir}"' \`dirs\`'
  67. alias    s    ${shdir} '-s\!* \`dirs\` ;if ( \${status} ) pushd +\${status} > /dev/null'
  68. alias    to    'pushd \!* > /dev/null ; '"${shdir}"' \`dirs\`'
  69. cat_eof
  70.     echo ''
  71.     cat ${tmpfile}
  72.     echo ''
  73.     echo -n "Do you want to add these aliases to .cshrc file? [y/n]: "
  74.     if ( "$<" == "y") cat ${tmpfile} >> ~/.cshrc
  75.     endif
  76. #---------------------------------------------------------------#
  77. #       Update directory stack save in .logout        #
  78. #---------------------------------------------------------------#
  79. if ( ! -e ~/saved_wd ) mkdir ~/saved_wd
  80. set msg = "save directory stack for next login"
  81. @ added = 0
  82. if ( -e ~/.logout ) @ added = `grep "${msg}" ~/.logout | wc -l`
  83. if ( ${added} == 0 ) then
  84.     echo "# ${msg}" > ${tmpfile}
  85.     echo 'dirs > ~/saved_wd/cwd.wd' >> ${tmpfile}
  86.     echo ''
  87.     cat ${tmpfile}
  88.     echo ''
  89.     echo -n "Do you want to add the line above to .logout file? [y/n]: "
  90.     if ( "$<" == "y") cat ${tmpfile} >> ~/.logout
  91.     endif
  92. #---------------------------------------------------------------#
  93. #        Add restore directory in .login            #
  94. #---------------------------------------------------------------#
  95. set msg = "restore last working directory stacks"
  96. @ added = 0
  97. if ( -e ~/.login ) @ added = `grep "${msg}" ~/.login | wc -l`
  98. #
  99. if ( ${added} == 0 ) then
  100.     cat > ${tmpfile} << cat_eof
  101. # ${msg}
  102. source ${dir}/restdir
  103. ${shdir} \`dirs\`
  104. cat_eof
  105. #
  106.     echo ''
  107.     cat ${tmpfile}
  108.     echo ''
  109.     echo -n "Do you want to add above 3 lines to .login file? [y/n]: "
  110.     if ( "$<" == "y") cat ${tmpfile} >> ~/.login
  111.     endif
  112. #---------------------------------------------------------------#
  113. #                Exit here                #
  114. #---------------------------------------------------------------#
  115. end:
  116. /bin/rm -f ${tmpfile}
  117. unset tmpfile dir msg added shdir
  118.