Dotfiles, utilities, and other apparatus.

filter-exec-raw 868B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env perl
  2. # Execute shell commands and include their output in the current buffer.
  3. #
  4. # See also: filter-exec for formatted output including the original command.
  5. use strict;
  6. use warnings;
  7. use 5.10.0;
  8. my $text;
  9. {
  10. # line separator:
  11. local $/ = undef;
  12. $text = <>;
  13. }
  14. $text =~ s{
  15. <!--[ ]exec-raw[ ](.*?)[ ]-->
  16. .*?
  17. <!--[ ]end[ ]-->
  18. }{
  19. handle_block($1);
  20. }egsx;
  21. print $text;
  22. sub handle_block {
  23. my ($command) = @_;
  24. my $result = `$command`;
  25. my $starter = 'exec-raw';
  26. return "<!-- $starter $command -->\n$result<!-- end -->";
  27. }
  28. __DATA__
  29. A self-test - use ,r in vim to check:
  30. <!-- exec-raw date -->
  31. Mon Oct 31 16:54:45 MDT 2016
  32. <!-- end -->
  33. <!-- exec-raw pwd -->
  34. /home/brennen/code/bpb-kit
  35. <!-- end -->
  36. <!-- exec -->
  37. $ ls
  38. apache2
  39. bpb-kit_1.0_all.deb
  40. home
  41. install.sh
  42. ns-control
  43. README.md
  44. tags
  45. <!-- end -->