sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit b25f6a1b7b3af5608ddfe7bace79451115eb2c34
parent 7c4205e185f793c07544537365161989ed7673cd
Author: Hamish Downer <dmishd@gmail.com>
Date:   Sun, 20 Feb 2011 21:51:45 +0000

Async mode: added method to copy file path to clipboard

Diffstat:
M lib/sup/modes/edit-message-async-mode.rb | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/lib/sup/modes/edit-message-async-mode.rb b/lib/sup/modes/edit-message-async-mode.rb
@@ -6,7 +6,7 @@ class EditMessageAsyncMode < LineCursorMode
 
   register_keymap do |k|
     k.add :edit_finished, "Finished editing message", 'E'
-#    k.add :path_to_clipboard, "Copy file path to the clipboard", :enter
+    k.add :path_to_clipboard, "Copy file path to the clipboard", :enter
   end
 
   def initialize parent_edit_mode, file_path, msg_subject
@@ -14,9 +14,11 @@ class EditMessageAsyncMode < LineCursorMode
     @file_path = file_path
     @orig_mtime = File.mtime @file_path
     
-    @text = ["", "Your message with subject:",  msg_subject, "is saved in a file:", "", @file_path, "", 
+    @text = ["ASYNC MESSAGE EDIT",
+             "", "Your message with subject:",  msg_subject, "is saved in a file:", "", @file_path, "", 
              "You can edit your message in the editor of your choice and continue to",
              "use sup while you edit your message.", "",
+             "Press <Enter> to have the file path copied to the clipboard.", "",
              "When you have finished editing, select this buffer and press 'E'.",]
     super() 
   end
@@ -29,7 +31,7 @@ class EditMessageAsyncMode < LineCursorMode
 
   def killable?
     if file_being_edited?
-      BufferManager.flash "Please check that #{@file_path} is not open in any editor and try again"
+      BufferManager.flash "Please check that #{@file_path} is not open in any editor and try again."
       return false
     end
 
@@ -45,7 +47,7 @@ protected
 
   def edit_finished
     if file_being_edited?
-      BufferManager.flash "Please check that #{@file_path} is not open in any editor and try again"
+      BufferManager.flash "Please check that #{@file_path} is not open in any editor and try again."
       return false
     end
 
@@ -54,6 +56,20 @@ protected
     true
   end
 
+  def path_to_clipboard
+    if system("which xsel > /dev/null 2>&1")
+      # linux/unix path
+      IO.popen('xsel --clipboard --input', 'r+') { |clipboard| clipboard.puts(@file_path) }
+      BufferManager.flash "Copied file path to clipboard."
+    elsif system("which pbcopy > /dev/null 2>&1")
+      # mac path
+      IO.popen('pbcopy', 'r+') { |clipboard| clipboard.puts(@file_path) }
+      BufferManager.flash "Copied file path to clipboard."
+    else
+      BufferManager.flash "No way to copy text to clipboard - try installing xsel."
+    end
+  end
+
   def file_being_edited?
     # check for common editor lock files
     vim_lock_file = File.join(File.dirname(@file_path), '.'+File.basename(@file_path)+'.swp')
@@ -69,9 +85,6 @@ protected
     File.mtime(@file_path) > @orig_mtime
   end
 
-  # to stop select doing anything
-  def select
-  end
 end
 
 end