diff options
author | Pål Grønås Drange <pgdr@equinor.com> | 2020-11-18 09:16:02 +0100 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2020-11-19 11:05:56 -0400 |
commit | 65e8e149a0dd2eb1c0f938904e6f62e91d4b29ce (patch) | |
tree | 6ba5c79a0eb5a2ad517a1620ac69b3db197fc69d | |
parent | 859c6e47b53410dbdcdc714385516bcb81710075 (diff) | |
download | moreutils-65e8e149a0dd2eb1c0f938904e6f62e91d4b29ce.tar.gz |
Add argument --suffix to vipe
Teaching vipe --suffix makes the underlying temporary file have a given
file extension to enable editors to understand the context in which they
are opened.
-rwxr-xr-x | vipe | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -15,6 +15,18 @@ edit the data that is being piped between programs. Your editor will have the full data being piped from command1 loaded into it, and when you close it, that data will be piped into command2. +=head1 ARGUMENTS + +vipe takes an argument --suffix that can be used to provide a file +extension to the temp file generated. This enables editors to provide +syntax highlighting and activate modes. For example, you can call vipe +like + + vipe --suffix csv + +to create a tempfile with .csv extensions which makes Emacs (or your +favorite editor) launch in CSV major mode. + =head1 ENVIRONMENT VARIABLES =over 4 @@ -40,10 +52,15 @@ Licensed under the GNU GPL. use warnings; use strict; use File::Temp q{tempfile}; +use Getopt::Long; $/=undef; -my ($fh, $tmp)=tempfile(UNLINK => 1); +my $suffix = ""; +GetOptions("suffix=s" => \$suffix) or die; +$suffix = ".$suffix" if $suffix =~ m/^[^.]/; + +my ($fh, $tmp)=tempfile(UNLINK => 1, SUFFIX => $suffix); die "cannot create tempfile" unless $fh; print ($fh <STDIN>) || die "write temp: $!"; close $fh; |