Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
executable file 76 lines (53 sloc) 1.44 KB
=head1 NAME
vipe - edit pipe
command1 | B<vipe> [...] | command2
vipe allows you to run your editor in the middle of a unix pipeline and
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
save, that data will be piped into command2.
Any extra arguments are passed as arguments to the editor.
=over 4
=item EDITOR
Editor to use.
=item VISUAL
Also supported to determine what editor to use.
=head1 AUTHOR
Copyright 2006 by Joey Hess <>
Licensed under the GNU GPL.
use warnings;
use strict;
use File::Temp q{tempfile};
my ($fh, $tmp)=tempfile();
die "cannot create tempfile" unless $fh;
print ($fh <STDIN>) || die "write temp: $!";
close $fh;
close STDIN;
open(STDIN, "</dev/tty") || die "reopen stdin: $!";
open(OUT, ">&STDOUT") || die "save stdout: $!";
close STDOUT;
open(STDOUT, ">/dev/tty") || die "reopen stdout: $!";
my @editor="vi";
if (-x "/usr/bin/editor") {
if (exists $ENV{EDITOR}) {
@editor=split(' ', $ENV{EDITOR});
if (exists $ENV{VISUAL}) {
@editor=split(' ', $ENV{VISUAL});
my $ret=system(@editor, @ARGV, $tmp);
if ($ret != 0) {
die "@editor exited nonzero, aborting\n";
open (IN, $tmp) || die "$0: cannot read $tmp: $!\n";
print (OUT <IN>) || die "write failure: $!";
close IN;