You are not logged in.
All urxvt users know this problem: you cannot paste from X clipboard into urxvt.
There are various workarounds. Many of them rely on synchronizing primary selection with clipboard (which I do not like. I don't want to "lose" a buffer). this can be in the form of autocutsel, or keybinds to do something like "xsel -bo | xsel -p", which has the additional disadvantage it requires an extra keyboard shortcut (one to sync the primary selection, one to do the actual paste).
I was wondering what would be a simple and clean way to paste the clipboard into urxvt (by using a -but only one- keyboard shortcut), without touching the primary selection.
I came up with putting this in my .xbindkeysrc
"xdotool type "$(xsel -bo)""
alt+Insert
But it's not perfect. I also tried with --clearmodifiers. If you try this out, you'll notice sometimes the paste will work, sometimes it will work half. Sometimes it replaces existing text, sometimes it will do nothing, and the best part is sometimes if you do backspace or stuff like that it behaves differently, I actually messed up my keyboard events with this.
Anyone an idea for the "perfect" way to go?
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Hmmm I think I may have fixed it
"xdotool type --delay 0 --clearmodifiers "$(xsel -bo)""
alt+Insert
this works pretty well. sometimes nothing at all happens, but usually it types the contents of my clipboard, without screwing my keymap or entering weird stuff
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
There was a post quite awhile ago that suggested adding the following perl script to /usr/lib/urxvt/perl/clipboard
#! perl
sub on_sel_grab {
my $query = quotemeta $_[0]->selection;
$query =~ s/\n/\\n/g;
$query =~ s/\r/\\r/g;
system( "echo -en " . $query . " | xsel -ibp" );
}
and then adding the following to .Xdefaults:
URxvt*perl-ext-common: default,matcher,clipboard
I've been using that quite happily for some time, and am able to copy/paste both ways to/from urxvt/firefox. I don't remember who posted it.
Scott
Offline
Also try this:
"xsel -x; xsel -o -b | xsel -i; xdotool click 2; xsel -x"
Offline
There was a post quite awhile ago that suggested adding the following perl script to /usr/lib/urxvt/perl/clipboard
#! perl sub on_sel_grab { my $query = quotemeta $_[0]->selection; $query =~ s/\n/\\n/g; $query =~ s/\r/\\r/g; system( "echo -en " . $query . " | xsel -ibp" ); }
and then adding the following to .Xdefaults:
URxvt*perl-ext-common: default,matcher,clipboard
I've been using that quite happily for some time, and am able to copy/paste both ways to/from urxvt/firefox. I don't remember who posted it.
Scott
do you know how this works? does it comply to my wishes? (don't override primary, allow pasting clipboard _into_ urxvt? this seems to be about going _from_ urxvt to something else)
Also try this:
"xsel -x; xsel -o -b | xsel -i; xdotool click 2; xsel -x"
great! this seems to work just as well, if not better then my initial trick thank you!
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Instead of xdotool click 2, for GUIs it is better to use xdotool key shift+Insert.
Offline
...snip...
do you know how this works? does it comply to my wishes? (don't override primary, allow pasting clipboard _into_ urxvt? this seems to be about going _from_ urxvt to something else)
You're correct in that it's only for going out of urxvt. And, it does in fact overwrite the primary selection too. Removing the 'p' switch will prevent that. But you should know that. You suffered through the whole thread with me!
Offline
"xsel -x; xsel -o -b | xsel -i; xdotool click 2; xsel -x"
Sorry for my stupid question... but where do I insert this... into .xbindkeysrc ?
and how would one edit it to be active on alt+v?
Is this the correct usage?
"xsel -x; xsel -o -b | xsel -i; xdotool key alt+v; xsel -x"
herm I pasted it in my .xbindkeysrc *I didnt have that file and had to make it... rebooted and I am unable to get this to work... I do have xdotool installed as well as xbindkeys.
Also -- I have been just using the compiz bind plugin for my keybindings... how would I edit it to not use xdotool/xbindkeys?
I tried the following but it didnt seem to do anything when triggered:
"xsel -x; xsel -o -b | xsel -i; xsel -x"
Last edited by ugkbunb (2009-09-16 06:33:41)
Offline
Wow... I always used a middle click on the urxvt window to paste whatever was highlighted... I can even alter what I paste with parcellite if I want.
Come to think of it though urxvt is the only program I have found that has ever required the middle click, though it can be used elsewhere.
I just make sure to keep Use Copy and Use Primary (Selection) checked in parcellite's preferences. I wouldn't recommend checking Synchronize clipboards though, the results get a little weird for me.
I keep getting distracted from my webserver project...
huh? oooh... shiny!
Offline
Instead of xdotool click 2, for GUIs it is better to use xdotool key shift+Insert.
why?
Dieter@be wrote:...snip...
do you know how this works? does it comply to my wishes? (don't override primary, allow pasting clipboard _into_ urxvt? this seems to be about going _from_ urxvt to something else)
You're correct in that it's only for going out of urxvt. And, it does in fact overwrite the primary selection too. Removing the 'p' switch will prevent that. But you should know that. You suffered through the whole thread with me!
Well actually i don't even have a problem with going out of urxvt. AFAIK all my apps support pasting from the primary buffer, so I'm good.
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
@Dieter: Because if you use it as a C+V substitute you expect it to paste at the text cursor while middle click will paste at the mouse cursor (or not at all if the mouse is outside the text box).
Offline
@Dieter: Because if you use it as a C+V substitute you expect it to paste at the text cursor while middle click will paste at the mouse cursor (or not at all if the mouse is outside the text box).
okay thanks. I also want to ask, why did you add the clause "for GUI tools.." ? is there a catch when using shift+insert? or is it better then middleclick in all aspects/use cases?
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
With "GUI" I mean GTK and such (also ncurses, where you can also disable the mouse and it's location sensitive). One catch is that it won't work if the keyboard is grabbed, like with dmenu, only middle click will work. Otherwise it seems to be the same.
Offline
With "GUI" I mean GTK and such (also ncurses, where you can also disable the mouse and it's location sensitive). One catch is that it won't work if the keyboard is grabbed, like with dmenu, only middle click will work. Otherwise it seems to be the same.
ah well, i actually consider this a missing feature in dmenu. If dmenu is running, i want shift+insert to paste in dmenu.
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Haven't read everything here, but I don't get the problem. What's wrong with just pasting with shift+insert?
Offline
Haven't read everything here, but I don't get the problem. What's wrong with just pasting with shift+insert?
it only works for primary selection buffer. not clipboard. E.g. in firefox when you click on a link/image/ you can do 'copy destination url', but not 'copy destination url to primary selection buffer'
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Strange - that example (copy destination url, paste with Shift-Insert) works fine by me. I can't say I don't have any problems with copy/paste in X, but mostly it works fine. Perhaps using vimperator in firefox solves some of the issues?
Offline
Strange - that example (copy destination url, paste with Shift-Insert) works fine by me. I can't say I don't have any problems with copy/paste in X, but mostly it works fine. Perhaps using vimperator in firefox solves some of the issues?
If anything, I should be using uzbl more
but I don't get your explanation. if you do "copy destination url" on a link it is in your clipboard. and AFAIK shift-insert = paste from primary selection, not from clipboard. at least that's how it is for me
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
but I don't get your explanation. if you do "copy destination url" on a link it is in your clipboard. and AFAIK shift-insert = paste from primary selection, not from clipboard. at least that's how it is for me
I'm afraid that is all there is to it, and that I can offer no explanation at the moment. When doing right click, copy link/image locations in both firefox (w. vimperator) or uzbl, i can paste it directly into urxvt with shift-insert. I am pretty sure that I have done no magic on my system to enable this feature, and I am positive I have no app running that facilitates this, but it might be an obscure side effect. I will try to hunt it down, given the time...
Offline
^^
woh--- yah it works for me too.... just have to make sure you have the cursor in the windows boundaries
Offline
I used this in my .xinitrc
autocutsel -fork &
autocutsel -selection PRIMARY -fork &
I believe this adds the clipboard buffer contents to the primary buffer.
What I was wondering if anyone knows a way to append the contents of the primary buffer to a file as soon as something is added to the primary buffer? Maybe using something xsel/xclip/sselp -o ? I know one could run a 'while true loop' every second but I was wondering if anyone knew of a more elegant solution.
I was thinking it might be nice to bind mod4+p to shift+insert and bind mod4+shift+p to a vertical demu list of the paste file I mentioned above.
Offline
I just use Ratpoison, which can simulate clicks
I have a binding (yep...one key) to simulate middle click.
I also have a binding that cycles frames on ALT+TAB, and while doing this it banishes the cursor to the lower right corner of the window, so it makes sure that I'm always on the selected frame when I paste. This also gets the nasty rat out of the way so double win for me
Last edited by Lich (2009-10-31 15:52:08)
Archlinux | ratpoison + evilwm | urxvtc | tmux
Offline
I've just found this page recently and made a solution:
#! perl -w
# Usage:
# URxvt.perl-ext-common: clipboard
# URxvt.keysym.Mod4-c: perl:clipboard:copy
# URxvt.keysym.Mod4-v: perl:clipboard:paste
# consult command "xmodmap" to see what your modifier mapped into.
sub copy {
my ($self) = @_;
my $pid = open( pout, "| xsel -ib" ) or die "fork";
print pout $self->selection;
close(pout) or die "close";
}
sub paste {
my ($self) = @_;
my $content = `xsel -ob` ;
$self->tt_write ($content);
}
sub on_user_command {
my ($self, $cmd) = @_;
if ($cmd eq "clipboard:copy") {
$self->copy;
}
if ($cmd eq "clipboard:paste") {
$self->paste;
}
}
save this script as /usr/lib/urxvt/perl/clipboard
then add lines in ~/.Xdefaults:
URxvt.perl-ext-common: clipboard
URxvt.keysym.Mod4-c: perl:clipboard:copy
URxvt.keysym.Mod4-v: perl:clipboard:paste
should have a good work for copy/paste via Win+C/V
Edit: changed the method piping to xsel, avoid escape sequence problem.
Last edited by realturner (2010-04-29 06:14:57)
Offline
I've just found this page recently and made a solution:
#! perl -w # Usage: # URxvt.perl-ext-common: clipboard # URxvt.keysym.Mod4-c: perl:clipboard:copy # URxvt.keysym.Mod4-v: perl:clipboard:paste # consult command "xmodmap" to see what your modifier mapped into. sub copy { my ($self) = @_; my $pid = open( pout, "| xsel -ib" ) or die "fork"; print pout $self->selection; close(pout) or die "close"; } sub paste { my ($self) = @_; my $content = `xsel -ob` ; $self->tt_write ($content); } sub on_user_command { my ($self, $cmd) = @_; if ($cmd eq "clipboard:copy") { $self->copy; } if ($cmd eq "clipboard:paste") { $self->paste; } }
save this script as /usr/lib/urxvt/perl/clipboard
then add lines in ~/.Xdefaults:URxvt.perl-ext-common: clipboard URxvt.keysym.Mod4-c: perl:clipboard:copy URxvt.keysym.Mod4-v: perl:clipboard:paste
should have a good work for copy/paste via Win+C/V
Edit: changed the method piping to xsel, avoid escape sequence problem.
wow! nice. thank you.
i didn't update this thread for a while, but i noticed that the earlier xdotool based solutions (including mine and Procyon's) sometimes just don't work, and I don't know why i will try this approach for a while
btw is there no recommed userspace location for urxvt scripts? otherwise, package your script please
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
FWIW I'm now using http://github.com/muennich/urxvt-perls/ … /clipboard (found it thanks to https://bbs.archlinux.org/viewtopic.php?id=102972), which is pretty similar to realturner's script (it doesn't do the `pid = .. or die` stuff, it can also paste while escaping all special characters)
And to answer my own question: you can put your scripts in a per-user location, which is explained @ http://github.com/muennich/urxvt-perls (short answer: set URxvt.perl-lib in your .Xdefaults)
the guy also has some other cool urxvt scripts
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline