package Psh
::Builtins
::Fc
;
=item * C<fc> -s [OLD=NEW] [command]
The last command or the last command starting with
[command] is re-executed after OLD is subsituted with NEW.
=item * C<fc> -p prepend [command]
Prepends the text prepend in front of the last command or the
last command starting with [command] and re-execute it.
Lists the last 15 commands, newest last
=item * C<fc> [-e editor] [range]
Edit the last command (or [range] commands) in either [editor],
C<$ENV{FCEDIT}>, C<$ENV{EDITOR}> or vi.
my $comnum=$#Psh::history
-1; # (otherwise we find the fc)
for (my $i=$comnum; $i>=0; $i--) {
if (Psh
::Util
::starts_with
($Psh::history
[$i],$command)) {
Psh
::Util
::print_error_i18n
('bi_fc_notfound');
local @ARGV = @
{shift()};
return (0,undef) unless $#Psh::history
;
Getopt
::Std
::getopts
('splre:',$opt);
for (my $i=@Psh::history
-$num; $i<@Psh::history
; $i++) {
Psh
::Util
::print_out
(' '.sprintf('%3d',$i+1).' '.$Psh::history
[$i]."\n");
my $comnum= _locate_command
($command);
return (0,undef) unless defined $comnum;
my $comtext=$Psh::history
[$comnum];
my ($old,$new)=$subst=~/^(.*?[^\\])\=(.*)$/;
Psh
::Util
::print_out
($comtext."\n");
Psh
::add_history
($comtext);
return Psh
::evl
($comtext);
my $prepend= shift @ARGV;
my $command= join ' ',@ARGV;
my $comnum= _locate_command
($command);
return (0,undef) unless defined $comnum;
my $comtext="$prepend $Psh::history[$comnum]";
Psh
::Util
::print_out
($comtext."\n");
Psh
::add_history
($comtext);
return Psh
::evl
($comtext);
if (!$Psh::interactive
) {
Psh
::Util
::print_error
("fc: not running interactively - cancelled\n");
my $file= Psh
::OS
::tmpnam
();
my $editor= Psh
::OS
::get_editor
($opt->{e
} || $ENV{FCEDIT
});
my $from=my $to=$#Psh::history
;
if ($ARGV[0]=~/^\s*(\d+)-(\d+)/) {
} elsif ($ARGV[0]=~/^\s*(\d+)\s*$/) {
if ($from<0 or $to<0 or $from>$#Psh::history
or
Psh
::Util
::print_error
("fc: specified range not in history\n");
if (open(FILE
,"> $file")) {
for (my $i=$from; $i<=$to; $i++) {
print FILE
$Psh::history
[$i-1]."\n";
Psh
::process_file
($file);