home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume3 / runfilter / runfilter
Encoding:
Text File  |  1989-02-03  |  1.2 KB  |  38 lines

  1. #!/bin/csh -f
  2. #
  3. # This takes standard input, assumes the first line is a command and the
  4. # rest is stuff to be filtered through the command.  It is for binding to
  5. # a key in textedit.  For example, put the following in your .textswrc:
  6. #    /*
  7. #     * Take the first line of the pending delete region as a
  8. #     * command and run the command with the rest of the region as
  9. #     * input.  The output (including error output) replaces the
  10. #     * region.  If you want to run a command with a ; in it, use
  11. #     * ()'s around it.
  12. #     */
  13. #    KEY_RIGHT(15)   FILTER
  14. #    runfilter
  15.  
  16. set prefix=/tmp/rf$$
  17. onintr cleanup
  18.  
  19. # Split up the input into $prefix.00 and .01.  The 00 file will contain
  20. #    the command and the 01 file will contain the text to be filtered.
  21. csplit -f $prefix. -s - 2
  22.  
  23. # Execute the command redirecting both standard out and error out to
  24. #    regular output so any errors show up in the editor.  Not using
  25. #    eval since the quotes in something like:
  26. #        sed 's/ /    /'
  27. #    disappear too soon and the shell turns the tab turns into a space.
  28. #    Using "cat $prefix.01 | ..." in case there are pipes embedded in
  29. #    the command.
  30. /bin/csh -f <<eof |& cat
  31. cat $prefix.01 | `cat $prefix.00`
  32. eof
  33.  
  34. # Clean up temp files.
  35. #
  36. cleanup:
  37. /bin/rm -f $prefix.00 $prefix.01
  38.