#! perl # Author: Raphaël Droz # Website: http://gitorious.org/~drzraf # Version: 0.1 # License: GPLv2 # TODO # use Term::ReadLine::Gnu; use POSIX (); sub on_user_command { my ($self, $cmd) = @_; if ($cmd eq "yank-return:true") { my ($row, $col) = $self->screen_cur; my $line = $self->ROW_t ($row - 1); # TODO: if (readline-previous-command-was-grep) # and no newline # and last line was not the prompt # bash: xxx command not found if ($line =~ /^bash:\s/) { $line =~ s/^bash:\s(.*?):\scommand not found\s*/$1/; $self->tt_write($line); } # ls -l (before "grep" because hours contain ":") elsif ($line =~ /^[ldp-][r-][w-][x-][r-][w-][x-][r-][w-][tx-]\s+/) { # $line =~ s/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+\S+\s+(.*?)\s+$/$1/; # (in ls -l), these two \d\d may be # the minutes or the two last digits of the year $line =~ s/^.*\d\d\s(.*?)\s+$/$1/; $self->tt_write($line); } # unzip elsif ($line =~ /^\s+inflating:/) { $line =~ s/^\s+inflating:\s+(.*?)\s+/$1/; $self->tt_write($line); } # dpkg -l elsif ($line =~ /^(ii|hi|rc)\s+/) { $line =~ s/^(ii|hi|rc)\s+(.*?)\s+.*/$1/; $self->tt_write($line); } elsif ($line =~ /:/) { my $login = getlogin; # prompt: return prev path if($line =~ /^$login@.*\$\s+$/) { $line =~ s/^.*?:(.*?)\s[\$#].*$/$1/; $self->tt_write($line); } # grep else { # TODO: custom regexp $line =~ s/^([^:\s]+):.*$/$1/; $self->tt_write($line); } } # wget elsif ($line =~ /^\s+$/) { my $pline = $self->ROW_t ($row - 2); $pline =~ s/^.*«(.*?)» sauvegardé \[.*$/$1/; $pline =~ s/^.*'(.*?)' saved \[.*$/$1/; $pline =~ s/^.*`(.*?)' saved \[.*$/$1/; $self->tt_write($pline); } # any other else { $line =~ s/\s+$//; $self->tt_write($line); } } () }