# NOTE: Derived from lib/Term/ReadLine/Zoid/ViCommand.pm.
# Changes made here will be lost when autosplit is run again.
# See AutoSplit.pm.
package Term::ReadLine::Zoid::ViCommand;

#line 1058 "lib/Term/ReadLine/Zoid/ViCommand.pm (autosplit into blib/lib/auto/Term/ReadLine/Zoid/ViCommand/shell.al)"
sub shell {
	my ($self, $string) = @_;

	my ($fh, $file);
	if ($string =~ /(?<!\\)%/) {
		eval 'require File::Temp' || return $self->bell;
		($fh, $file) = File::Temp::tempfile('PERL_RL_Zoid_XXXXX', DIR => File::Spec->tmpdir);
		print $fh join "\n", @{$$self{lines}};
		close $fh;
		$string =~ s/(\\)\%|\%/$1 ? '%' : $file/ge;
	}

	#print STDERR "system: $string\n";
	print { $$self{OUT} } "\n";
	my $error = (exists $$self{config}{shell})
		? $$self{config}{shell}->($string) : system( $string ) ;

	if ($error) { printf { $$self{OUT} } "\nshell returned %s\n\n", $error >> 8  }
	elsif ($file) {
		open TMP, $file or return $self->bell;
		@{$$self{lines}} = map {chomp; $_} (<TMP>);
		close TMP;
		$$self{pos} = [ length($$self{lines}[-1]), $#{$$self{lines}} ];
	}
	$$self{_buffer} = 0;
	unlink $file if $file;

	return 1;
}

# end of Term::ReadLine::Zoid::ViCommand::shell
1;
