Subject: [sup-devel] [PATCH] 'u' in thread-view-mode copies URL to X selection

From: Chris Parsons <[email-masked]>
Date: Thu, 04 Nov 2010 15:49:03 +0000

I know there's been some discussion about opening URLs from e-mails in Sup, and
because many people use Sup via an SSH session, client-side solutions are not
universally useful... but here is a patch that seems to copy a URL on the
currently highlighted line to the X selection buffer. (From there I use Kupfer
http://kaizer.se/wiki/kupfer/ to open the link in a web client.)
Obviously you can do something similar with a mouse but I use a
netbook and try to avoid using the trackpad if I can.

It relies on having the program xsel available in your path.

I've never fiddled in Ruby before so accept my apologies if the lines are
ridiculous, and also if this has been done before by others.

For the reasons I mention (not universal, requires xsel) I don't
expect it to make it into the Sup code base but I put it out here in
case it suits anyone else.
---
 lib/sup/modes/line-cursor-mode.rb |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/lib/sup/modes/line-cursor-mode.rb b/lib/sup/modes/line-cursor-mode.rb
index 1cae994..e65cbee 100644
--- a/lib/sup/modes/line-cursor-mode.rb
+++ b/lib/sup/modes/line-cursor-mode.rb
@@ -8,6 +8,7 @@ class LineCursorMode < ScrollMode
     k.add :cursor_down, "Move cursor down one line", :down, 'j'
     k.add :cursor_up, "Move cursor up one line", :up, 'k'
     k.add :select, "Select this item", :enter
+    k.add :selurl, "Copy URL to selection", 'u'
   end
 
   attr_reader :curpos
@@ -90,6 +91,18 @@ protected
     set_cursor_pos botline - 1 if @curpos > botline - 1
   end
 
+  def selurl
+     regex = /(?:http|https|mailto):\/\/\S+/i
+     this_line = self[curpos][0][1]
+     match = regex.match(this_line)
+     return if not match
+
+     output = pipe_to_process("xsel -i") do |stream|
+        stream.print match
+     end
+     BufferManager.flash "selected url #{match}"
+  end
+
   def cursor_down
     call_load_more_callbacks buffer.content_height if @curpos >= lines - [buffer.content_height/2,1].max
     return false unless @curpos < lines - 1
-- 
1.7.3.2
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Alvaro Herrera <[email-masked]>
Date: Thu, 04 Nov 2010 14:54:55 -0300

> netbook and try to avoid using the trackpad if I can.

It seems like this should be more generally doable with a hook.

-- 
Álvaro Herrera <[email-masked]>
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Michael Stapelberg <[email-masked]>
Date: Fri, 05 Nov 2010 11:37:49 +0100

Hi Chris,

> universally useful... but here is a patch that seems to copy a URL on the
Not sure which side you mean with client-side now, but I usually want to open
the URL on the computer I am currently using (not always the side on which sup
is running, but always the side on which my terminal is running). For that, I
use the mark-and-yank plugin for urxvt:

http://www.jukie.net/bart/blog/urxvt-url-yank

Best regards,
Michael