aboutsummaryrefslogtreecommitdiffstats
path: root/.urxvt/ext/clipboard
diff options
context:
space:
mode:
authorWeitian LI <liweitianux@gmail.com>2014-06-13 21:12:21 +0800
committerWeitian LI <liweitianux@gmail.com>2014-06-13 21:12:21 +0800
commit78f7be4e4b6501b15b5fefc9f7824bbadf0daf2a (patch)
treeb761e28709e4a6f45458c323b8870150827ef831 /.urxvt/ext/clipboard
parente1ce158f65c472b7c8d14c04fce94c85bc881a6c (diff)
downloaddotfiles-78f7be4e4b6501b15b5fefc9f7824bbadf0daf2a.tar.bz2
Added various dotfiles.
* Xresources * profile, xprofile, xinitrc * bash (aliases, logout, profile, rc, completion) * gitconfig * gtkrc and gtk-bookmarks * i3 configs (with py3status configs) * i3status.conf * lftp/rc * tmux.conf * xbindkeysrc * mpdconf * ncmpcpp (config and keys) * sbclrc * vifm (vifmrc, colors) * urxvt (perl extensions) * conkyrc (and conky/cronograph configs)
Diffstat (limited to '.urxvt/ext/clipboard')
-rw-r--r--.urxvt/ext/clipboard109
1 files changed, 109 insertions, 0 deletions
diff --git a/.urxvt/ext/clipboard b/.urxvt/ext/clipboard
new file mode 100644
index 0000000..8e71792
--- /dev/null
+++ b/.urxvt/ext/clipboard
@@ -0,0 +1,109 @@
+#! perl -w
+# Author: Bert Muennich
+# Website: http://www.github.com/muennich/urxvt-perls
+# 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
+
+# Options:
+# URxvt.clipboard.autocopy: If true, PRIMARY overwrites clipboard
+
+# 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';
+
+ if ($self->x_resource('clipboard.autocopy') eq 'true') {
+ $self->enable(sel_grab => \&sel_grab);
+ }
+
+ ()
+}
+
+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;
+ }
+
+ ()
+}
+
+sub sel_grab {
+ my ($self) = @_;
+
+ $self->copy;
+
+ ()
+}