You are not logged in.

#1 2012-09-23 18:39:39

jtan189
Member
Registered: 2012-07-12
Posts: 8

[SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

I've spent an embarrassing amount of time trying to figure this out. I figured I might have better luck posting on the forums?

My problem is that I can't seem to be able to make things work as I want.

Here's what I want:

  • Ability to copy to the X Clipboard buffer (e.g. using ctrl-c in Chromium) and paste into urxvt (e.g. using middle click).

  • Ability to copy to the X Primary buffer (e.g. highlighting text within urxvt) and paste into Chromium (e.g. using middle click or ctrl-v)

Here's what I don't want:

  • Lose functionality of the perl keyboard-select and url-select extensions.

  • Have text I've highlighted in an application (such as Chromium) be copied into the X Primary buffer (and replace whatever was there before).

Currently, I have rxvt-unicode-patched and urxvt-perls installed and up-to-date. I also have xsel and xclip installed. Yet, text copied within urxvt is not able to be pasted into Chromium using ctrl-v (or shift-insert). If I do

echo "<paste whatever I've highlighted within urxvt>" | xsel -ib

or

echo "<paste whatever I've highlighted within urxvt>" | xclip -sel clip

, then I'm able to paste into Chromium using ctrl-v/shift-insert. But I don't want to have to do that every time. Furthermore, I find it really annoying that anything I highlight in Chromium is copied to (and replaces what was previously in) the X Primary buffer. This is because I often copy stuff from urxvt, switch to Chromium, highlight what I want to replace, and then end up losing what I originally wanted to copy over in the first place.

Here's the relevant part of my .Xresources:

URxvt.perl-ext-common: 	  	default,clipboard,url-select,keyboard-select
URxvt*geometry:			112x22  
URxvt*font:           	  	xft:terminus:size=10
URxvt.scrollBar:		false
URxvt.keysym.M-u:    	  	perl:url-select:select_next
URxvt.keysym.M-Escape:		perl:keyboard-select:activate
URxvt.keysym.M-s:		perl:keyboard-select:search
URxvt.url-select.launcher:	chromium
URxvt.url-select.underline:	true
URxvt.urgentOnBell:	  	true
!URxvt.clipboard.copycmd:  	xsel -ib
!URxvt.clipboard.pastecmd: 	xsel -ob

I left the following out because I don't want those mappings; I'd rather just paste in the terminal using middle click/shift-insert.

URxvt.keysym.M-c:   perl:clipboard:copy
URxvt.keysym.M-v:   perl:clipboard:paste
URxvt.keysym.M-C-v: perl:clipboard:paste_escaped

I'm not sure if it's helpful, but here's my .xinitrc:

#!/bin/sh

# update x resources db
xrdb -merge ~/.Xresources 

# add directory that contains terminus to the font path
xset +fp /usr/share/fonts/local
xset fp rehash

xsetroot -cursor_name left_ptr &
mpd &
dropboxd &

xmonad

Any ideas on what I might do to solve my problem?

Last edited by jtan189 (2012-10-30 03:48:00)

Offline

#2 2012-09-23 19:09:37

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

So you left out the part that indicates the keymappings to copy/paste and you are wondering why it doesn't work?  Am I reading this correctly?

Offline

#3 2012-09-23 20:18:02

jtan189
Member
Registered: 2012-07-12
Posts: 8

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

Adding

URxvt.keysym.M-c:   perl:clipboard:copy
URxvt.keysym.M-v:   perl:clipboard:paste
URxvt.keysym.M-C-v: perl:clipboard:paste_escaped

allows me to successfully copy text from urxvt to the X-Clipboard  (and then paste into Chromium using ctrl-v or shift-insert). However, I'm looking for a way that doesn't require the extra step of issuing the M-v command. I want any text copied into the X-Primary buffer (which happens automatically when I highlight text within urxvt) to be automatically put into the X-Clipboard. Also, I do not want text I highlight in an application like Chromium to be copied into the X-Primary buffer (and replace whatever was already in there), which is currently happening.

Last edited by jtan189 (2012-09-23 20:20:45)

Offline

#4 2012-09-23 21:19:36

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

Don't some clipboard managers have methods of syncing the clipboard/primary?  Honestly, I just don't use the primary buffer as my laptop does not have a middle button.  So I simply use the clipboard. 

I don't understand how the M-v is an extra step, could you explain that more?  For me, M-c in rxvt-unicode or C-c in anything else copies, and then C-v, shift-insert, or M-v in rxvt-unicode pastes. 

As far as teh primary buffer in other applications, I am totally unfamiliar with such things.

Offline

#5 2012-09-24 00:20:34

jtan189
Member
Registered: 2012-07-12
Posts: 8

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

Sorry, I meant to say "M-c" instead of "M-v" in my last post.

After thinking some more about it, I'm not sure it's really possible for me to get what I want. Or at least not with the existing tools. Ideally, I want Chromium (or whatever application) to leave the primary buffer alone (as far as putting selected text into it) and just copy/paste using the clipboard. I also want the content of the clipboard to sync with the primary buffer, so that it is available to urxvt. On the other end, I want whatever I put into the primary buffer in urxvt (by highlighting text) to be put into the clipboard for Chromium to use. That means that I'll need to use something like autocutsel to sync the primary buffer with the clipboard.

The problem is that Chromium (and I assume other applications) don't leave the primary buffer alone. So if I did use something like autocutsel, whenever I highlighted text (included the contents of the URL bar in order to replace them), the primary buffer and clipboard would be overwritten with the new selection. Which is another thing I don't want.

I guess I might have to live with using the urxvt-perls clipboard extension (along with M-c) to copy text to the clipboard. I don't want to enable the M-v binding, because I use that already within emacs. I hope nothing else will use M-c...

Offline

#6 2012-10-28 10:30:55

jelloir
Member
From: Rye, VIC, Australia
Registered: 2010-03-02
Posts: 4

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

@jtan189,

I debugged this and found a solution.

You will need to download the latest version from github (version in Arch is out of date).

Then follow this - https://github.com/muennich/urxvt-perls/issues/32 which reads:  "I altered the 3 occurences of "sel_grab" to "on_sel_grab" and this has fixed the issue"

With any luck muennich will update it soon anyway and hopefully it will make it into Arch as well soon.

Edit:  I should also point out you need to have "URxvt.clipboard.autocopy:   true" in ~/.Xdefaults which I just pasted from URxvt to Firefox using auto selected copy smile

Last edited by jelloir (2012-10-28 10:35:43)


Trying out Arch after using Debian Sid for a long time...

Offline

#7 2012-10-28 11:14:39

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

This will help you.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#8 2012-10-28 21:58:13

jelloir
Member
From: Rye, VIC, Australia
Registered: 2010-03-02
Posts: 4

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

Turns out my solution was wrong and it was simply a typo in the code that enables auto copy.  muennich has updated it now so simply grabbing the latest version and enabling "URxvt.clipboard.autocopy:   true" in ~/.Xdefaults is all thats needed.


Trying out Arch after using Debian Sid for a long time...

Offline

#9 2012-10-30 03:46:51

jtan189
Member
Registered: 2012-07-12
Posts: 8

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

@jelloir: Perfect! That's exactly the kind of functionality I was looking for. Thanks for updating the thread with the solution (and thanks to muennich for the fix).

Offline

#10 2013-03-08 21:20:27

ravisghosh
Member
From: Intergalactic Spaces
Registered: 2006-10-12
Posts: 516
Website

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

Folks, a noobish question here.

I added the script in /usr/lib/urxvt/perl/clipboard as a plain text file and added the required lines in .Xdefaults. Still, I'm not able to use Ctrl+C/V to copy/paste from urxvt. Am I doing something wrong here?

Offline

#11 2013-03-08 21:48:01

jtan189
Member
Registered: 2012-07-12
Posts: 8

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

Assuming the lines you added to your .Xdefaults were

URxvt.perl-ext-common: ...,clipboard
URxvt.keysym.M-c:   perl:clipboard:copy
URxvt.keysym.M-v:   perl:clipboard:paste
URxvt.keysym.M-C-v: perl:clipboard:paste_escaped

, then you should be using Alt instead of Ctrl.

Offline

#12 2013-03-09 07:25:25

ravisghosh
Member
From: Intergalactic Spaces
Registered: 2006-10-12
Posts: 516
Website

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

jtan189 wrote:

Assuming the lines you added to your .Xdefaults were

URxvt.perl-ext-common: ...,clipboard
URxvt.keysym.M-c:   perl:clipboard:copy
URxvt.keysym.M-v:   perl:clipboard:paste
URxvt.keysym.M-C-v: perl:clipboard:paste_escaped

, then you should be using Alt instead of Ctrl.

Thanks jtan. I tried that but that too doesn't work. Should the clipboard file be renamed as clipboard.pl?

Offline

#13 2013-03-09 18:04:02

jtan189
Member
Registered: 2012-07-12
Posts: 8

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

I don't think it needs to be renamed. Is there a reason you didn't just install using the AUR package?

Offline

#14 2013-03-09 19:15:05

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

I do recall that script was broken when I tried to use it, and had to use something else in its place... it has been a while, but this is what I have as /usr/lib/urxvt/perl/clipboard

%  cat clipboard
#! perl -w
# Author:   Bert Muennich
# Website:  http://www.github.com/muennich/urxvt-perls
# Version:  2.0
# License:  GPLv2

# Use keyboard shortcuts to copy the selection to the clipboard and to paste
# the clipboard contents (optionally escaping all special characters).
# Requires xsel to be installed!

# Usage: put the following lines in your .Xdefaults/.Xresources:
#   URxvt.perl-ext-common: ...,clipboard
#   URxvt.keysym.M-c:   perl:clipboard:copy
#   URxvt.keysym.M-v:   perl:clipboard:paste
#   URxvt.keysym.M-C-v: perl:clipboard:paste_escaped

# You can also overwrite the system commands to use for copying/pasting.
# The default ones are:
#   URxvt.clipboard.copycmd:  xsel -ib
#   URxvt.clipboard.pastecmd: xsel -ob
# If you prefer xclip, then put these lines in your .Xdefaults/.Xresources:
#   URxvt.clipboard.copycmd:  xclip -i -selection clipboard
#   URxvt.clipboard.pastecmd: xclip -o -selection clipboard
# On Mac OS X, put these lines in your .Xdefaults/.Xresources:
#   URxvt.clipboard.copycmd:  pbcopy
#   URxvt.clipboard.pastecmd: pbpaste

# The use of the functions should be self-explanatory!

use strict;

sub on_start {
	my ($self) = @_;

	$self->{copy_cmd} = $self->x_resource('clipboard.copycmd') || 'xsel -ib';
	$self->{paste_cmd} = $self->x_resource('clipboard.pastecmd') || 'xsel -ob';

	()
}

sub copy {
	my ($self) = @_;

	if (open(CLIPBOARD, "| $self->{copy_cmd}")) {
		my $sel = $self->selection();
		utf8::encode($sel);
		print CLIPBOARD $sel;
		close(CLIPBOARD);
	} else {
		print STDERR "error running '$self->{copy_cmd}': $!\n";
	}

	()
}

sub paste {
	my ($self) = @_;

	my $str = `$self->{paste_cmd}`;
	if ($? == 0) {
		$self->tt_paste($str);
	} else {
		print STDERR "error running '$self->{paste_cmd}': $!\n";
	}

	()
}

sub paste_escaped {
	my ($self) = @_;

	my $str = `$self->{paste_cmd}`;
	if ($? == 0) {
		$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
		$self->tt_paste($str);
	} else {
		print STDERR "error running '$self->{paste_cmd}': $!\n";
	}

	()
}

sub on_user_command {
	my ($self, $cmd) = @_;

	if ($cmd eq "clipboard:copy") {
	   $self->copy;
	} elsif ($cmd eq "clipboard:paste") {
	   $self->paste;
	} elsif ($cmd eq "clipboard:paste_escaped") {
	   $self->paste_escaped;
	}

	()
}

Is yours the same?  If not, this works for me.

Offline

#15 2013-03-10 08:35:03

ravisghosh
Member
From: Intergalactic Spaces
Registered: 2006-10-12
Posts: 516
Website

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

@jtan - I thought creating a text file would be easier than installing a package from aur smile

@WonderWoofy - I replaced your script, but it didn't work either.

Finally, I installed the urxvt-perls package from Community and placed the following text in .Xdefaults:

URxvt.perl-ext-common: ...,clipboard
URxvt.keysym.M-c:   perl:clipboard:copy
URxvt.keysym.M-v:   perl:clipboard:paste
URxvt.keysym.M-C-v: perl:clipboard:paste_escaped

Still not able to copy/paste using right Alt+C/V. Am I using the right keys?

Offline

#16 2013-03-10 19:49:01

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

I am not sure exactly, how .Xdefaults works, but I use .Xresources, and then have it merged with xrdb upon the start of X.  So I have this:

% cat ~/.Xresources
...
URxvt*keysym.M-c:	    perl:clipboard:copy
URxvt*keysym.M-v:	    perl:clipboard:paste
URxvt*keysym.M-C-p:	    perl:clipboard:paste_escaped
...

Then I have this in ~/.xinitrc

% cat ~/.xinitrc
...
[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources
...

Offline

#17 2013-03-11 19:49:03

ravisghosh
Member
From: Intergalactic Spaces
Registered: 2006-10-12
Posts: 516
Website

Re: [SOLVED] Copy/paste problem using rxvt-unicode-patched and urxvt-perls

WonderWoofy wrote:

I am not sure exactly, how .Xdefaults works, but I use .Xresources, and then have it merged with xrdb upon the start of X.  So I have this:

% cat ~/.Xresources
...
URxvt*keysym.M-c:	    perl:clipboard:copy
URxvt*keysym.M-v:	    perl:clipboard:paste
URxvt*keysym.M-C-p:	    perl:clipboard:paste_escaped
...

Then I have this in ~/.xinitrc

% cat ~/.xinitrc
...
[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources
...

Apparently, this didn't help either sad  I first tried with xinitrc and then with fluxbox's startup file, no luck in either case.

Offline

Board footer

Powered by FluxBB