#!/usr/bin/env perl # Execute shell commands and include their output in the current buffer. # # This is brittle and probably very subject to quoting problems, but in # practice it's been a useful hack for local notes and technical writing. # # See also: # # - filter-exec for formatted output including the original command # # - filter-exec-stdin for a version that passes the contained block to # stdin of the executed command use strict; use warnings; use 5.10.0; my $text; { # Line separator: local $/ = undef; $text = <>; } # HTML quote markers / commands: $text =~ s{ .*? }{ handle_block('', ''); }egsx; # Vim/VimWiki-style markers: $text =~ s/ [{]{3}exec-raw[ ](.*?)$ .*? [}]{3} / handle_block('{{{', $1, '', '}}}'); /egmsx; print $text; sub handle_block { my ($start, $command, $command_end, $end) = @_; my $result = `$command`; return "${start}exec-raw ${command}${command_end}\n${result}${end}"; } __DATA__ A self-test - use ,r in vim to check: {{{exec-raw date Thu 02 Apr 2020 11:49:22 AM MDT }}} Thu 02 Apr 2020 11:49:22 AM MDT /home/brennen/notes $ ls ~/bin/filter-exec-raw /home/brennen/bin/filter-exec-raw