From: Chris Parsons <cjparsons1@yahoo.co.uk>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] 'u' in thread-view-mode copies URL to X selection
Date: Thu, 04 Nov 2010 15:49:03 +0000 [thread overview]
Message-ID: <1288885683-sup-601@chris-eee> (raw)
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
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
next reply other threads:[~2010-11-04 17:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-04 15:49 Chris Parsons [this message]
2010-11-04 17:54 ` Alvaro Herrera
2010-11-05 10:37 ` Michael Stapelberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1288885683-sup-601@chris-eee \
--to=cjparsons1@yahoo.co.uk \
--cc=sup-devel@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox