summaryrefslogtreecommitdiffstats
authorRaghavendra D Prabhu <[email protected]>2011-05-23 18:51:49 (GMT)
committer Raghavendra D Prabhu <[email protected]>2011-05-23 18:51:49 (GMT)
commited0da5af540201cca4b1440835d12a7869dcc601 (patch) (side-by-side diff)
tree7370f8108bf6dff95647c9c8c0fbebf7e1e1d28e
downloadrxvt-scripts-ed0da5af540201cca4b1440835d12a7869dcc601.zip
rxvt-scripts-ed0da5af540201cca4b1440835d12a7869dcc601.tar.gz
rxvt-scripts-ed0da5af540201cca4b1440835d12a7869dcc601.tar.bz2
Rxvt scriptsHEADmaster
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xautochangie57
-rwxr-xr-xchangie44
-rwxr-xr-xmark-yank-urls307
-rw-r--r--pasteit54
-rwxr-xr-xsynfocus20
5 files changed, 482 insertions, 0 deletions
diff --git a/autochangie b/autochangie
new file mode 100755
index 0000000..0d49f35
--- a/dev/null
+++ b/autochangie
@@ -0,0 +1,57 @@
+#! perl
+# To dynamically change font size of your current font.
+# Bind a key like --> URxvt.keysym.M-3: perl:changefont:toggle
+#
+# Define font size range like
+# URxvt.frange: 10,13
+# Your current font size is automatically added to it
+
+sub on_start {
+ my ($term) = @_;
+ $term->{'sizearr'} = [];
+ my @tmp = split /,/, $term->x_resource ("frange") || qw(13);
+ my $font = $term->resource('font');
+ my $xsize = (split(/-/,(split(/:/, $font))[1]))[1];
+ push @tmp, $xsize;
+ $term->{'origindex'} = $#tmp;
+ $term->{'sizearr'} = \@tmp;
+}
+
+sub on_user_command {
+ my ($term, $cmd) = @_;
+ if ($cmd eq 'changie:toggle-down') {
+ toggle($term,-1);
+ }
+ else {
+ toggle($term,+1);
+ }
+ ()
+}
+
+sub toggle {
+ my ($self,$inc) = @_;
+ my $index = $self->{'origindex'};
+ my $font = $self->resource('font');
+ my @tmp = @{$self->{'sizearr'}};
+ $index = $index + (1 * $inc);
+ $index %= @tmp;
+ $font =~ s/(?<=-)[0-9]+(?=:)/$tmp[$index]/;
+ $self->overlay_simple (0, -1, "Size set to $tmp[$index]");
+ $self->cmd_parse("\033]710;$font\007");
+ $self->{'origindex'} = $index;
+ ()
+}
+
+sub on_map_notifyxxx {
+ my ($term) = @_;
+ my $autochange = $term->x_resource ("autotoggle") || 1;
+ if ($autochange == 1){
+ my $str = `tail -2 /tmp/xmonad.log | grep Xye | awk -F ' . ' '{ print $3 }'`;
+ if ($str =~ m{/([0-9]):.*/.*<([0-9]).*>}) {
+ if ($1 < $3) {
+ toggle($term,+1);
+ }
+ }
+ }
+ ()
+}
diff --git a/changie b/changie
new file mode 100755
index 0000000..22aa1cd
--- a/dev/null
+++ b/changie
@@ -0,0 +1,44 @@
+#! perl
+# To dynamically change font size of your current font.
+# Bind a key like --> URxvt.keysym.M-3: perl:changefont:toggle
+#
+# Define font size range like
+# URxvt.frange: 10,13
+# Your current font size is automatically added to it
+
+sub on_start {
+ my ($term) = @_;
+ $term->{'sizearr'} = [];
+ my @tmp = split /,/, $term->x_resource ("frange") || qw(13);
+ my $font = $term->resource('font');
+ my $xsize = (split(/-/,(split(/:/, $font))[1]))[1];
+ push @tmp, $xsize;
+ $term->{'origindex'} = $#tmp;
+ $term->{'sizearr'} = \@tmp;
+}
+
+sub on_user_command {
+ my ($term, $cmd) = @_;
+ if ($cmd eq 'changie:toggle-down') {
+ toggle($term,-1);
+ }
+ else {
+ toggle($term,+1);
+ }
+ ()
+}
+
+sub toggle {
+ my ($self,$inc) = @_;
+ my $index = $self->{'origindex'};
+ my $font = $self->resource('font');
+ my @tmp = @{$self->{'sizearr'}};
+ $index = $index + (1 * $inc);
+ $index %= @tmp;
+ $font =~ s/(?<=-)[0-9]+(?=:)/$tmp[$index]/;
+ $self->overlay_simple (0, -1, "Size set to $tmp[$index]");
+ $self->cmd_parse("\033]710;$font\007");
+ $self->{'origindex'} = $index;
+ ()
+}
+
diff --git a/mark-yank-urls b/mark-yank-urls
new file mode 100755
index 0000000..25bfdb6
--- a/dev/null
+++ b/mark-yank-urls
@@ -0,0 +1,307 @@
+#!/usr/bin/perl
+# Author: Bart Trojanowski <[email protected]>
+# Website: http://www.jukie.net/~bart/blog/urxvt-url-yank
+# License: GPLv2
+# Modified by: Raghavendra Prabhu raghu d0t prabhu 13 AT google mail
+
+use strict;
+use warnings;
+
+my $url_matcher = qr{(
+ (?:https?://|ftp://|news://|mailto:|file://|www\.)[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~#]+
+ [ab-zA-Z0-9\-\@;\/?&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic)
+)}x;
+
+
+sub on_start {
+ my ($term) = @_;
+
+ $term->{have_Clipboard} = eval { require Clipboard; };
+ if ($term->{have_Clipboard}) {
+ import Clipboard;
+ }
+
+# eval { require Regexp::Common::URI };
+# require Regexp::Common;
+# Regexp::Common->import('URI');
+#
+# $url_matcher = $Regexp::Common::RE{URI}{HTTP};
+# }
+
+ $term->{browser} = $term->x_resource ("urlLauncher") || "x-www-browser";
+ $term->{browser2} = $term->x_resource ("launcher2") || "x-www-browser";
+ ()
+}
+
+sub on_line_update {
+ my ($term, $row) = @_;
+
+ # Fetch the line that has changed.
+ my $line = $term->line($row);
+ my $text = $line->t;
+
+
+ # Find and underline URLs.
+ while ($text =~ /($url_matcher)/g) {
+ my $url = $1;
+ my $rend = $line->r;
+
+ # Mark all characters as underlined. we _must_ not toggle underline, as
+ # we might get called on an already-marked URL.
+ my $underlineURLs = $term->x_resource ('underlineURLs') || 'false';
+ if($underlineURLs eq 'true') {
+ my ($first, $last) = ($-[1], $+[1] - 1);
+
+ --$last if $url =~ s/["']$//;
+
+ $_ |= urxvt::RS_Uline for @{$rend}[$first .. $last];
+
+ $line->r($rend);
+ }
+ }
+# Clipboard->copy($url);
+# system("echo abcdefef | xclip -i");
+ ()
+}
+
+sub on_button_release {
+ my ($term, $event) = @_;
+
+ my $mask = $term->ModLevel3Mask | $term->ModMetaMask
+ | urxvt::ShiftMask | urxvt::ControlMask;
+
+ if ($event->{button} == 2 && ($event->{state} & $mask) == 0) {
+ my $row = $event->{row};
+ my $col = $event->{col};
+
+ my $line = $term->line ($row);
+ my $text = $line->t;
+
+ while ($text =~ /($url_matcher)/g) {
+ my ($url, $first, $last) = ($1, $-[1], $+[1]);
+
+ if($first <= $col && $last >= $col) {
+ $url =~ s/["']$//;
+ $term->exec_async($term->{browser}, $url);
+ return 1;
+ }
+ }
+ }
+
+ ()
+}
+
+
+my $mark_mode_active = 0;
+my %mod = ( 'control' => 0, 'shift' => 0 );
+my $url_selected = -1;
+my @url_db = ();
+
+
+sub do_scan_for_urls {
+ my ($term) = @_;
+
+ @url_db = ();
+
+ my $row_start = $term->top_row;
+ my $row_end = $term->nrow;
+
+ for my $row ($row_start .. $row_end) {
+
+ # Fetch the line that has changed.
+ my $line = $term->line ($row);
+ my $text = $line->t;
+
+ # Find all urls (if any).
+ while ($text =~ /($url_matcher)/g) {
+ my $rend = $line->r;
+
+ my ($url, $first, $last) = ($1, $-[1], $+[1] - 1);
+
+ --$last if $url =~ s/["']$//;
+
+ my %h = (
+ row => $row,
+ col_from => $first,
+ col_to => $last,
+ url => $url,
+ );
+
+ push @url_db, \%h;
+ }
+ }
+ return $#url_db + 1;
+}
+
+
+sub on_user_command {
+ my ($term, $cmd) = @_;
+
+ activate_mark_mode($term) if $cmd eq 'mark-yank-urls:activate_mark_mode';
+
+ ()
+}
+
+sub on_key_press {
+ my ($term, $event, $keysym, $octets) = @_;
+
+ if ($keysym == 65507) { # <control>
+ $mod{control} = 1;
+
+ } elsif ($keysym == 65505) { # <shift>
+ $mod{shift} = 1;
+
+ }
+
+ # Ignore all input when we are active.
+ $mark_mode_active && return 1;
+
+ ()
+}
+
+sub on_key_release {
+ my ($term, $event, $keysym, $octets) = @_;
+
+ if ($mark_mode_active) {
+ my $ch = chr($keysym);
+
+ if ($keysym == 65307) { # <esc>
+ deactivate_mark_mode ($term);
+ return 1;
+
+ } elsif ($keysym == 65293) { # <enter>
+ my $url = get_active_url($term);
+ $term->exec_async($term->{browser}, $url);
+ deactivate_mark_mode ($term);
+ return 1;
+
+ } elsif ($keysym == 65507) { # <control>
+ $mod{control} = 0;
+ return 1;
+
+ } elsif ($keysym == 93) { # ]
+ my $url = get_active_url($term);
+ $term->exec_async($term->{browser2}, $url);
+ deactivate_mark_mode ($term);
+ return 1;
+ } elsif ($keysym == 65505) { # <shift>
+ $mod{shift} = 0;
+ return 1;
+
+ } elsif ($mod{control} && (($ch eq 'n') || ($ch eq 'p'))) {
+ # ^n and ^p to cycle list
+ my $dir = ($ch eq 'n') ? 1 : -1;
+ move_highlight ($term, $dir);
+
+ } elsif ($ch eq 'y') { # y
+ do_copy ($term);
+ deactivate_mark_mode ($term);
+ return 1;
+
+ }
+
+ return 1;
+ }
+
+ ()
+}
+
+sub get_active_url {
+ my ($term) = @_;
+ my $max = $#url_db + 1;
+
+ return if $url_selected < 0 || $url_selected >= $max;
+ return if not defined $url_db[$url_selected];
+ my $o = $url_db[$url_selected];
+ my %h = %$o;
+
+ return $h{url};
+}
+
+sub do_copy {
+ my ($term) = @_;
+
+ my $text = get_active_url ($term);
+
+ if ($term->{have_Clipboard}) {
+ Clipboard->copy($text);
+ } else {
+ $text =~ s/\(["|><&()]\)/\\$1/;
+ system ("echo -n \"$text\" | xclip -i");
+ }
+}
+
+sub move_highlight {
+ my ($term, $dir) = @_;
+ my $max = $#url_db + 1;
+
+ do_highlight ($term, 0);
+
+ $url_selected = ($max + $url_selected + $dir) % $max;
+
+ do_highlight ($term, 1);
+
+ $term->want_refresh;
+}
+
+sub do_highlight {
+ my ($term, $enable) = @_;
+ my $max = $#url_db + 1;
+
+ return if $url_selected < 0 || $url_selected >= $max;
+ return if not defined $url_db[$url_selected];
+
+ my $o = $url_db[$url_selected];
+ my %h = %$o;
+
+ my $row = $h{row};
+ my $line = $term->line ($row);
+ my $text = $line->t;
+ my $rend = $line->r;
+
+ if ($enable) {
+ $_ |= urxvt::RS_RVid
+ for @{$rend}[ $h{col_from} .. $h{col_to}];
+
+ # make it visible
+ $term->view_start ( $row < 0 ? $row : 0 );
+
+ } else {
+ $_ &= ~urxvt::RS_RVid
+ for @{$rend}[ $h{col_from} .. $h{col_to}];
+ }
+
+ $line->r ($rend);
+}
+
+sub activate_mark_mode {
+ my ($term) = @_;
+
+ if ($mark_mode_active) {
+
+ move_highlight ($term, -1);
+
+ } elsif ( do_scan_for_urls ($term) ) {
+
+ $term->{save_view_start} = $term->view_start;
+
+ move_highlight ($term, 0);
+
+ $mark_mode_active=1 if ($url_selected > -1);
+ }
+}
+
+sub deactivate_mark_mode {
+ my ($term) = @_;
+
+ do_highlight ($term, 0);
+
+ $mark_mode_active = 0;
+ $url_selected = -1;
+
+ $term->view_start ($term->{save_view_start});
+ $term->want_refresh;
+}
+
+# vim: set et ts=4 sw=4:
diff --git a/pasteit b/pasteit
new file mode 100644
index 0000000..f286342
--- a/dev/null
+++ b/pasteit
@@ -0,0 +1,54 @@
+#! perl
+# Original paste script modified for num of lines > 1 case
+
+sub msg {
+ my ($self, $msg) = @_;
+
+ $self->{overlay} = $self->overlay (0, -1, $self->ncol, 2, urxvt::OVERLAY_RSTYLE, 0);
+ $self->{overlay}->set (0, 0, $msg);
+}
+
+sub on_tt_paste {
+ my ($self, $str) = @_;
+
+ my $count = ($str =~ tr/\012\015//);
+
+ if ($count == 1){
+ chomp($str);
+ $self->{paste} = \$str;
+ $self->leave;
+ return;
+ }
+
+ return unless $count;
+
+ $self->{paste} = \$str;
+ $self->msg ("Paste of $count lines, continue? (y/n)");
+ my $preview = substr $self->locale_decode ($str), 0, $self->ncol;
+ $preview =~ s/\n/\\n/g;
+ $self->{overlay}->set (0, 1, $self->special_encode ($preview));
+ $self->enable (key_press => \&key_press);
+
+ 1
+}
+
+sub leave {
+ my ($self) = @_;
+
+ $self->{paste} = undef;
+ delete $self->{overlay};
+ $self->disable ("key_press");
+}
+
+sub key_press {
+ my ($self, $event, $keysym, $string) = @_;
+
+ if ($keysym == 121) { # y
+ $self->tt_paste (${$self->{paste}});
+ $self->leave;
+ } elsif ($keysym == 110) { # n
+ $self->leave;
+ }
+
+ 1
+}
diff --git a/synfocus b/synfocus
new file mode 100755
index 0000000..fe660a5
--- a/dev/null
+++ b/synfocus
@@ -0,0 +1,20 @@
+#! perl
+
+
+sub on_focus_out {
+ my ($self) = @_;
+ my $dest=`xdotool getactivewindow getwindowname 2>/dev/null`;
+ if ($dest =~ /screen/) { return; }
+ `synclient TouchpadOff=0`;
+ #$! == 0 && `~/bin/notify-send "Urxvt" "Focus back"`;
+ ()
+}
+
+
+sub on_focus_in {
+ my ($self) = @_;
+ #`xdotool getactivewindow getwindowname &>>/tmp/xlog`;
+ `synclient TouchpadOff=1`;
+ #$! == 0 && `~/bin/notify-send "Urxvt" "I'm back. For your keys only"`;
+ ()
+}