home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff342.lzh / SKsh / stuff.sksh < prev    next >
Text File  |  1990-04-15  |  7KB  |  229 lines

  1.  
  2. #*************************************************************************
  3. # This file contains functions and aliases which can be cut out and put
  4. # in your .skshrc file.  They are not included there by default, since
  5. # many people will not want them, or will want modified versions.
  6. # These commands should operate with SKsh version 1.3 or later.
  7. # They are also simple skeletons which can be expanded to add features.
  8. #
  9. # Also, please note that these commands have not been tested extensively.
  10. #*************************************************************************
  11.  
  12.  
  13. #*************************************************************************
  14. # This is a "man" function which can be used to retrieve documentation
  15. # files stored in a MAN: directory.  These files (which are often
  16. # included with public domain software as "readme" files) should be
  17. # copied to a name such as "MAN:prog.MAN".  Then, "man prog" can be used
  18. # to retrieve the files with the $PAGER command.
  19. #*************************************************************************
  20.  
  21. function man {
  22.    if [ -z "$PAGER" ] then PAGER='more'; fi
  23.  
  24.    if [ ! -f "MAN:$1.MAN" ]
  25.    then
  26.       echo "No manual entry for $1"
  27.    else
  28.       $PAGER "MAN:$1.MAN"
  29.    fi
  30. }
  31.  
  32.  
  33. #*************************************************************************
  34. #  This function accepts a number of parameters, and prompts the user
  35. #  for whether these files should be deleted.  For example, "qrm *.o"
  36. #  would prompt the user at each .o file.  Answering "Y" or "y" causes
  37. #  the file to be removed; otherwise, it is ignored.  A useful extention
  38. #  would look at only the first character of the response, thus allowing
  39. #  "yes" to be used in place of "y".
  40. #*************************************************************************
  41.  
  42. function qrm {    # query rm
  43.    local ans
  44.  
  45.    for file in $*
  46.    do
  47.       echo -n "Remove $file ? "
  48.       read ans
  49.  
  50.       if [ "$ans" = 'y' -o "$ans" = 'Y' ]
  51.       then
  52.          rm -v "$file"
  53.       fi
  54.    done
  55. }
  56.  
  57.  
  58. #*************************************************************************
  59. # This alias will remove emacs backup files by using the "qrm" function
  60. # defined above.  It could be extended to remove ".o" files, or anything
  61. # else.
  62. #*************************************************************************
  63.  
  64. alias clean='qrm *~'
  65.  
  66.  
  67. #*************************************************************************
  68. # The following functions implement directory push and pop operations.
  69. # The first, pushd, accepts one argument.  It cd's to that directory, but
  70. # pushes the current working directory onto a stack, first, so that it
  71. # can later be retrieved with a popd.
  72. #*************************************************************************
  73.  
  74. function pushd {
  75.    if [ $# -ne 1 ]
  76.    then
  77.       echo "Usage: $0 new_dir"
  78.    else
  79.       DIRSTACK="$PWD,$DIRSTACK"
  80.       export DIRSTACK
  81.       cd "$1"
  82.    fi
  83. }
  84.  
  85. #*************************************************************************
  86. # This function implements the popd operation.  It accepts no arguments,
  87. # and simply pops a directory off the stack and returns to that point.
  88. # it complains if the directory stack is empty.
  89. #*************************************************************************
  90.  
  91. function popd {
  92.    local comma_pos new_dir
  93.  
  94.    if [ $# -ne 0 ]
  95.    then
  96.       echo "Usage: $0"
  97.       return
  98.    elif [ -z "$DIRSTACK" ]
  99.    then
  100.       echo 'The directory stack is empty'
  101.       return
  102.    fi
  103.       
  104.    comma_pos = $(expr index "$DIRSTACK" ',')
  105.    new_dir   = $(expr substr "$DIRSTACK" 1 $(expr $comma_pos - 1))
  106.    DIRSTACK  = $(expr substr "$DIRSTACK" $(expr $comma_pos + 1) 32000)
  107.    export DIRSTACK
  108.    cd "$new_dir"
  109. }
  110.  
  111.  
  112. #*************************************************************************
  113. # These aliases clear and print the directory stack, respectively.  The
  114. # directory stack will be printed with a trailing comma, which is how it
  115. # is stored.  This could be cleaned up quite simply.
  116. #*************************************************************************
  117.  
  118. alias cleard='DIRSTACK=""'
  119. alias dstack='echo "$DIRSTACK"'
  120.  
  121. #*************************************************************************
  122. # Ths function insert all files in the current directory except .o
  123. # files into the current complist.  It also inserts the contents of the
  124. # COMPLIST variable.
  125. #*************************************************************************
  126.  
  127. function cget {
  128.    complist -e
  129.    complist -a !*.o
  130.    complist -a $COMPLIST
  131. }
  132.  
  133. #*************************************************************************
  134. # Aliases and functions to make zoo files a bit easier to manipulate.
  135. # The "zmore" function
  136. #*************************************************************************
  137.  
  138. alias zp='zoo -print'
  139. alias zl='zoo -list'
  140. alias zx='zoo -extract'
  141. alias za='zoo -add'
  142.  
  143. function zmore {
  144.  
  145.   local zoofile tmpfile
  146.  
  147.   if [ $# -lt 2 ]
  148.   then
  149.      echo "Usage: $0 zoofile file1..."
  150.      return;
  151.   fi
  152.  
  153.   if [ -f "$1" ] then zoofile="$1"; else zoofile="$1.zoo"; fi
  154.  
  155.   if [ ! -f "$zoofile" ]
  156.   then
  157.      echo "$0: $zoofile not found"
  158.      return
  159.   fi
  160.  
  161.   shift
  162.  
  163.   tmpfile="pipe:tmp_$CLINUM.$CMDNUM"
  164.  
  165.   if [ -z "$PAGER" ] then PAGER='more'; fi
  166.  
  167.   srun -o "$tmpfile" $(which zoo) -print "$zoofile" $*
  168.   $PAGER "$tmpfile"
  169. }
  170.  
  171.  
  172. #*************************************************************************
  173. # This function insert all files from a 'zoo' archive into the current
  174. # complist.  They also insert the contents of the COMPLIST variable.
  175. #*************************************************************************
  176.  
  177. function _zadd {
  178.    shift 2    # get rid of "Archive blah.zoo"
  179.    complist -a $*
  180. }
  181.  
  182. function zget {
  183.  
  184.    local zoofile zlist
  185.  
  186.    if [ -f "$1" ] then zoofile="$1"; else zoofile="$1.zoo"; fi
  187.  
  188.    if [ ! -f "$zoofile" ]
  189.    then
  190.       echo "$0: $zoofile not found"
  191.       return
  192.    fi
  193.  
  194.    complist -e
  195.  
  196.    zlist=$(zoo lf1 "$zoofile")
  197.    
  198.    _zadd $zlist
  199.    complist -a $COMPLIST
  200. }
  201.  
  202.  
  203. #*************************************************************************
  204. # This function extracts a zoo file in its own sub-directory, then
  205. # deletes the original
  206. #*************************************************************************
  207.  
  208. function zxdir {
  209.    local file dname zooname
  210.  
  211.    for file in $*
  212.    do
  213.       dname=$(extname -v "$file")
  214.       zooname="$dname.zoo"
  215.       if [ ! -d "$dname" ] then mkdir "$dname"; fi
  216.  
  217.       mv "$zooname" "$dname"; cd "$dname"
  218.  
  219.       if zoo -extract "$zooname" >nil:
  220.       then
  221.          rm "$zooname"
  222.       else
  223.          echo "Extract Failed!"
  224.       fi
  225.       cd ..
  226.    done
  227. }
  228.  
  229.