- #!/usr/bin/env perl
-
- # Execute shell commands and include their output in the current buffer.
- #
- # See also: filter-exec for formatted output including the original command.
-
- use strict;
- use warnings;
- use 5.10.0;
-
- my $text;
- {
- # line separator:
- local $/ = undef;
- $text = <>;
- }
-
- $text =~ s{
- <!--[ ]exec-raw[ ](.*?)[ ]-->
- .*?
- <!--[ ]end[ ]-->
- }{
- handle_block($1);
- }egsx;
-
- print $text;
-
- sub handle_block {
- my ($command) = @_;
- my $result = `$command`;
- my $starter = 'exec-raw';
- return "<!-- $starter $command -->\n$result<!-- end -->";
- }
-
- __DATA__
- A self-test - use ,r in vim to check:
-
- <!-- exec-raw date -->
- Mon Oct 31 16:54:45 MDT 2016
- <!-- end -->
-
- <!-- exec-raw pwd -->
- /home/brennen/code/bpb-kit
- <!-- end -->
-
- <!-- exec -->
-
- $ ls
- apache2
- bpb-kit_1.0_all.deb
- home
- install.sh
- ns-control
- README.md
- tags
-
- <!-- end -->
|