home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk381.lzh / SKsh / stuff.sksh < prev    next >
Text File  |  1990-10-20  |  9KB  |  296 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.    elif [ ! -d "$1" ]
  79.    then
  80.       echo "$0: Can't cd to $1"
  81.    else
  82.       DIRSTACK="$PWD,$DIRSTACK"
  83.       export -l DIRSTACK
  84.       cd "$1"
  85.    fi
  86. }
  87.  
  88. #*************************************************************************
  89. # This function implements the popd operation.  It accepts no arguments,
  90. # and simply pops a directory off the stack and returns to that point.
  91. # it complains if the directory stack is empty.
  92. #*************************************************************************
  93.  
  94. function popd {
  95.    local comma_pos new_dir
  96.  
  97.    if [ $# -ne 0 ]
  98.    then
  99.       echo "Usage: $0"
  100.       return
  101.    elif [ -z "$DIRSTACK" ]
  102.    then
  103.       echo 'The directory stack is empty'
  104.       return
  105.    fi
  106.       
  107.    comma_pos = $(expr index "$DIRSTACK" ',')
  108.    new_dir   = $(expr substr "$DIRSTACK" 1 $(expr $comma_pos - 1))
  109.    DIRSTACK  = $(expr substr "$DIRSTACK" $(expr $comma_pos + 1) 32000)
  110.    export -l DIRSTACK
  111.  
  112.    if cd "$new_dir"; then true
  113.    else echo "$0: Can't cd to $new_dir."
  114.    fi
  115. }
  116.  
  117.  
  118. #*************************************************************************
  119. # These aliases clear and print the directory stack, respectively.  The
  120. # directory stack will be printed with a trailing comma, which is how it
  121. # is stored.  This could be cleaned up quite simply.
  122. #*************************************************************************
  123.  
  124. alias cleard='DIRSTACK=""'
  125. alias dstack='echo "$DIRSTACK"'
  126.  
  127. #*************************************************************************
  128. # Ths function insert all files in the current directory except .o
  129. # files into the current complist.  It also inserts the contents of the
  130. # COMPLIST variable.
  131. #*************************************************************************
  132.  
  133. function cget {
  134.    complist -e
  135.    complist -a !*.o
  136.    complist -a $COMPLIST
  137. }
  138.  
  139. #*************************************************************************
  140. # Aliases and functions to make zoo files a bit easier to manipulate.
  141. # The "zmore" function
  142. #*************************************************************************
  143.  
  144. alias zp='zoo -print'
  145. alias zl='zoo -list'
  146. alias zx='zoo -extract'
  147. alias za='zoo -add'
  148.  
  149. function zmore {
  150.  
  151.   local zoofile tmpfile
  152.  
  153.   if [ $# -lt 2 ]
  154.   then
  155.      echo "Usage: $0 zoofile file1..."
  156.      return;
  157.   fi
  158.  
  159.   if [ -f "$1" ] then zoofile="$1"; else zoofile="$1.zoo"; fi
  160.  
  161.   if [ ! -f "$zoofile" ]
  162.   then
  163.      echo "$0: $zoofile not found"
  164.      return
  165.   fi
  166.  
  167.   shift
  168.  
  169.   tmpfile="pipe:tmp_$CLINUM.$CMDNUM"
  170.  
  171.   if [ -z "$PAGER" ] then PAGER='more'; fi
  172.  
  173.   srun -o "$tmpfile" $(which zoo) -print "$zoofile" $*
  174.   $PAGER "$tmpfile"
  175. }
  176.  
  177.  
  178. #*************************************************************************
  179. # This function insert all files from a 'zoo' archive into the current
  180. # complist.  They also insert the contents of the COMPLIST variable.
  181. #*************************************************************************
  182.  
  183. function _zadd {
  184.    shift 2    # get rid of "Archive blah.zoo"
  185.    complist -a $*
  186. }
  187.  
  188. function zget {
  189.  
  190.    local zoofile zlist
  191.  
  192.    if [ -f "$1" ] then zoofile="$1"; else zoofile="$1.zoo"; fi
  193.  
  194.    if [ ! -f "$zoofile" ]
  195.    then
  196.       echo "$0: $zoofile not found"
  197.       return
  198.    fi
  199.  
  200.    complist -e
  201.  
  202.    zlist=$(zoo lf1 "$zoofile")
  203.    
  204.    _zadd $zlist
  205.    complist -a $COMPLIST
  206. }
  207.  
  208.  
  209. #*************************************************************************
  210. # This function extracts a zoo file in its own sub-directory, then
  211. # deletes the original
  212. #*************************************************************************
  213.  
  214. function zxdir {
  215.    local file dname zooname
  216.  
  217.    for file in $*
  218.    do
  219.       dname=$(extname -v "$file")
  220.       zooname="$dname.zoo"
  221.       if [ ! -d "$dname" ] then mkdir "$dname"; fi
  222.  
  223.       mv "$zooname" "$dname"; cd "$dname"
  224.  
  225.       if zoo -extract "$zooname" >nil:
  226.       then
  227.          rm "$zooname"
  228.       else
  229.          echo "Extract Failed!"
  230.       fi
  231.       cd ..
  232.    done
  233. }
  234.  
  235.  
  236. #*************************************************************************
  237. # This function sets emacs mode editing
  238. #*************************************************************************
  239.  
  240. function emacs_mode {
  241.  
  242.    setmap -r                           # reset the keymap
  243.  
  244.    setmap -m 0 BOL ISM '#' PIO ACC     # comment out line macro
  245.  
  246.    setmap 0  8 BS   9  CC1  1  BOL  2 LFT   4  DEL  127 DEL  5 EOL  6 RHT \
  247.              7 ZAP  11 KEL  14 DN   15 EXE  16 UP   18  SRH 27 @1 155 @2 \
  248.              12 RDL 26 TIM  21 REP 20 SPC 25 YNK
  249.  
  250.    setmap 1  27 CC1  = CC2  \* CC3  8 BDW  f FWW  b BKW  d DLW  \. ILP \
  251.              \/ ILT  '<' HOL  '>' TOL  '#' '!0'  48 ERC  49 ERC  50 ERC \
  252.              51 ERC  52 ERC  53 ERC  54 ERC  55 ERC  56 ERC  57 ERC
  253.  
  254.    setmap 2  A UP   B DN  C RHT  D LFT  T HOL  S TOL  ' ' @3 \
  255.              48 FNK  49 FNK  50 FNK  51 FNK  52 FNK  53 FNK  54 FNK \
  256.              55 FNK  56 FNK  57 FNK
  257.  
  258.    setmap 3  A BKW  @ FWW
  259. }
  260.  
  261.  
  262. #*************************************************************************
  263. # This function sets vi-mode editing
  264. #*************************************************************************
  265.  
  266. function vi_mode {
  267.  
  268.    setmap -r # reset the keymap
  269.  
  270.    setmap -n 1
  271.    setmap -e 1 2
  272.  
  273.    setmap -m 0 BOL GK0
  274.    setmap -m 1 EOL GK0
  275.    setmap -m 2 RHT GK0
  276.    setmap -m 3 BOL ISM '#' PIO ACC
  277.  
  278.    setmap 0 27 @1  8 BS  9 CC1 12 RDL 155 @3 127 DEL 20 SPC
  279.  
  280.    setmap 1  k UP  j DN  h LFT  l RHT  x DEL 10 ACC 13 ACC  i @0  a '!2' \
  281.           d @2  27 CC1 $ EOL  \^ BOL \/ SRH  155 @3  n SRH  8 BS w FWW \
  282.           W FWW  b BKW B BKW - UP + DN D KEL R TIM _ ILP \* CC3 12 RDL \
  283.           = CC2  X BS  127 DEL  A '!1' I '!0' '#' '!3'  p YNK 49 ERC \
  284.           50 ERC  51 ERC  52 ERC  53 ERC  54 ERC  55 ERC  56 ERC  57 ERC
  285.  
  286.    setmap 2  w DLW  $ KEL  d ZAP c DEL
  287.  
  288.    setmap 3  A UP   B DN  C RHT  D LFT  T HOL  S TOL  ' ' @4 \
  289.              48 FNK  49 FNK  50 FNK  51 FNK  52 FNK  53 FNK  54 FNK \
  290.              55 FNK  56 FNK  57 FNK
  291.    
  292.    setmap 4  A BKW  @ FWW
  293. }
  294.  
  295.  
  296.