You are not logged in.
I want Urxvt to copy whatever I just wrote in the terminal without using the mouse, I just want to type a single combination such as Ctrl-m. I'm not sure if there's any easier way to do it, so I tried writing a perl function:
sub tox {
my ($self) = @_;
my $text;
my $PS1='>>> ';
# get the last non-empty line
for (my $i = 0; $i < $self->nrow; $i ++) {
my $line = $self->line($i);
next if ($line->beg != $i);
next unless $line->t;
$text = $line->t;
}
# remove PS1, rprompt and copy to clipboard
$text =~ s/$PS1//;
my $rprompt = ( ${$self->env}{'PWD'} eq ${$self->env}{'HOME'} ?
'~' : ${$self->env}{'PWD'} );
$text =~ s/\s*$rprompt$//; # remove spaces and rprompt
system( "echo -en \"" . $text . "\" | xsel -i" );
}
The problem is, I'm not sure how to remove the rprompt, which shows the working directory. I tried to obtain the working directory with ${$self->env}{'PWD'}, but the value seems to be the working directory of the parent terminal. e.g., when I open urxvt, cd to /tmp and open urxvt inside this terminal, then PWD is /tmp. If I cd to /home, PWD remains /tmp. Same problem with $HOME.
If anyone has an idea how to obtain the actual working directory or maybe knows another possibility, I'm glad to hear it.
Last edited by sigma91 (2013-05-02 16:59:47)
Offline
Moving to programming and scripting...
Offline
If you want to copy text from/to yout clipboard (which is what I understood so far), You should look at:
http://search.cpan.org/~king/Clipboard- … ipboard.pm
You can then retrieve the clipboard with Clipboard->paste() and write to it with Clipboard->copy('foo');
Maybe it helps!
Offline
The above code uses xsel to paste to clipboard:
system( "echo -en \"" . $text . "\" | xsel -i" );
So the perl module doesn't solve my problem.
Here's an example of what I'm trying to achieve:
I'm in the folder /tmp and I just typed 'fdisk -l'. The terminal looks like this:
>>> fdisk -l /tmp
>>> is my PS1, on the right is my rprompt, which shows the current directory (/tmp). The variable $text gives me this whole string, but I just want to copy 'fdisk -l'. The PS1 can easily be deleted using
$text =~ s/$PS1//;
my question is, how to delete the rprompt?
Offline