diff options
| author | jason | 2018-07-31 16:07:17 -0600 |
|---|---|---|
| committer | jason | 2018-07-31 16:08:02 -0600 |
| commit | 234af80b65053c4954b27e3a2ff9eb2d332dbedc (patch) | |
| tree | 07f087a209af310c4c82cbd2bb444fef899d9c27 /xorg | |
| parent | 39a882b49ce869559329bb4b8703c7504a6276b2 (diff) | |
| download | dotfiles-234af80b65053c4954b27e3a2ff9eb2d332dbedc.tar.gz dotfiles-234af80b65053c4954b27e3a2ff9eb2d332dbedc.zip | |
add clipboard script for urxvt
Diffstat (limited to 'xorg')
| -rw-r--r-- | xorg/.urxvt/ext/clipboard | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/xorg/.urxvt/ext/clipboard b/xorg/.urxvt/ext/clipboard new file mode 100644 index 0000000..63c0ea2 --- /dev/null +++ b/xorg/.urxvt/ext/clipboard | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | # Author: Bert Muennich | ||
| 3 | # Website: http://www.github.com/muennich/urxvt-perls | ||
| 4 | # License: GPLv2 | ||
| 5 | |||
| 6 | # Use keyboard shortcuts to copy the selection to the clipboard and to paste | ||
| 7 | # the clipboard contents (optionally escaping all special characters). | ||
| 8 | # Requires xsel to be installed! | ||
| 9 | |||
| 10 | # Usage: put the following lines in your .Xdefaults/.Xresources: | ||
| 11 | # URxvt.perl-ext-common: ...,clipboard | ||
| 12 | # URxvt.keysym.M-c: perl:clipboard:copy | ||
| 13 | # URxvt.keysym.M-v: perl:clipboard:paste | ||
| 14 | # URxvt.keysym.M-C-v: perl:clipboard:paste_escaped | ||
| 15 | |||
| 16 | # Options: | ||
| 17 | # URxvt.clipboard.autocopy: If true, PRIMARY overwrites clipboard | ||
| 18 | |||
| 19 | # You can also overwrite the system commands to use for copying/pasting. | ||
| 20 | # The default ones are: | ||
| 21 | # URxvt.clipboard.copycmd: xsel -ib | ||
| 22 | # URxvt.clipboard.pastecmd: xsel -ob | ||
| 23 | # If you prefer xclip, then put these lines in your .Xdefaults/.Xresources: | ||
| 24 | # URxvt.clipboard.copycmd: xclip -i -selection clipboard | ||
| 25 | # URxvt.clipboard.pastecmd: xclip -o -selection clipboard | ||
| 26 | # On Mac OS X, put these lines in your .Xdefaults/.Xresources: | ||
| 27 | # URxvt.clipboard.copycmd: pbcopy | ||
| 28 | # URxvt.clipboard.pastecmd: pbpaste | ||
| 29 | |||
| 30 | # The use of the functions should be self-explanatory! | ||
| 31 | |||
| 32 | |||
| 33 | use strict; | ||
| 34 | use warnings; | ||
| 35 | |||
| 36 | sub on_start { | ||
| 37 | my ($self) = @_; | ||
| 38 | |||
| 39 | $self->{copy_cmd} = $self->x_resource('clipboard.copycmd') || 'xsel -ib'; | ||
| 40 | $self->{paste_cmd} = $self->x_resource('clipboard.pastecmd') || 'xsel -ob'; | ||
| 41 | |||
| 42 | if ($self->x_resource('clipboard.autocopy') eq 'true') { | ||
| 43 | $self->enable(sel_grab => \&sel_grab); | ||
| 44 | } | ||
| 45 | |||
| 46 | () | ||
| 47 | } | ||
| 48 | |||
| 49 | sub copy { | ||
| 50 | my ($self) = @_; | ||
| 51 | |||
| 52 | if (open(CLIPBOARD, "| $self->{copy_cmd}")) { | ||
| 53 | my $sel = $self->selection(); | ||
| 54 | utf8::encode($sel); | ||
| 55 | print CLIPBOARD $sel; | ||
| 56 | close(CLIPBOARD); | ||
| 57 | } else { | ||
| 58 | print STDERR "error running '$self->{copy_cmd}': $!\n"; | ||
| 59 | } | ||
| 60 | |||
| 61 | () | ||
| 62 | } | ||
| 63 | |||
| 64 | sub paste { | ||
| 65 | my ($self) = @_; | ||
| 66 | |||
| 67 | my $str = `$self->{paste_cmd}`; | ||
| 68 | if ($? == 0) { | ||
| 69 | $self->tt_paste($str); | ||
| 70 | } else { | ||
| 71 | print STDERR "error running '$self->{paste_cmd}': $!\n"; | ||
| 72 | } | ||
| 73 | |||
| 74 | () | ||
| 75 | } | ||
| 76 | |||
| 77 | sub paste_escaped { | ||
| 78 | my ($self) = @_; | ||
| 79 | |||
| 80 | my $str = `$self->{paste_cmd}`; | ||
| 81 | if ($? == 0) { | ||
| 82 | $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\$1/g; | ||
| 83 | $self->tt_paste($str); | ||
| 84 | } else { | ||
| 85 | print STDERR "error running '$self->{paste_cmd}': $!\n"; | ||
| 86 | } | ||
| 87 | |||
| 88 | () | ||
| 89 | } | ||
| 90 | |||
| 91 | sub on_action { | ||
| 92 | my ($self, $action) = @_; | ||
| 93 | |||
| 94 | on_user_command($self, "clipboard:" . $action); | ||
| 95 | } | ||
| 96 | |||
| 97 | sub on_user_command { | ||
| 98 | my ($self, $cmd) = @_; | ||
| 99 | |||
| 100 | if ($cmd eq "clipboard:copy") { | ||
| 101 | $self->copy; | ||
| 102 | } elsif ($cmd eq "clipboard:paste") { | ||
| 103 | $self->paste; | ||
| 104 | } elsif ($cmd eq "clipboard:paste_escaped") { | ||
| 105 | $self->paste_escaped; | ||
| 106 | } | ||
| 107 | |||
| 108 | () | ||
| 109 | } | ||
| 110 | |||
| 111 | sub sel_grab { | ||
| 112 | my ($self) = @_; | ||
| 113 | |||
| 114 | $self->copy; | ||
| 115 | |||
| 116 | () | ||
| 117 | } | ||
| 118 | |||