commit 1d4d50c339403022e8a1699eeb2d1fcd577dcd6b
parent d1f99547946833e5a1849e8dfb39b7604803e2c7
Author: Shawn Axsom <shawn.axsom@rooksecurity.com>
Date: Sat, 25 Apr 2015 17:54:28 -0400
Merge branch 'master' of https://github.com/insanum/sncli
Diffstat:
4 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/simplenote_cli/clipboard.py b/simplenote_cli/clipboard.py
@@ -0,0 +1,18 @@
+import os
+from distutils import spawn
+
+
+class Clipboard(object):
+ def __init__(self):
+ self.copy_command = self.get_copy_command()
+
+ def get_copy_command(self):
+ if (spawn.find_executable('xsel')):
+ return 'echo "%s" | xsel -ib'
+ if (spawn.find_executable('pbcopy')):
+ return 'echo "%s" | pbcopy'
+ return None
+
+ def copy(self, text):
+ if (self.copy_command):
+ os.system(self.copy_command % text)
diff --git a/simplenote_cli/config.py b/simplenote_cli/config.py
@@ -70,6 +70,7 @@ def __init__(self):
'kb_note_pin' : 'p',
'kb_note_markdown' : 'm',
'kb_note_tags' : 't',
+ 'kb_copy_note_text' : 'y',
'clr_default_fg' : 'default',
'clr_default_bg' : 'default',
@@ -189,6 +190,7 @@ def __init__(self):
self.keybinds['note_pin'] = [ cp.get(cfg_sec, 'kb_note_pin'), [ 'titles', 'notes' ], 'Pin note' ]
self.keybinds['note_markdown'] = [ cp.get(cfg_sec, 'kb_note_markdown'), [ 'titles', 'notes' ], 'Flag note as markdown' ]
self.keybinds['note_tags'] = [ cp.get(cfg_sec, 'kb_note_tags'), [ 'titles', 'notes' ], 'Edit note tags' ]
+ self.keybinds['copy_note_text'] = [ cp.get(cfg_sec, 'kb_copy_note_text'), [ 'notes' ], 'Copy line (xsel/pbcopy)' ]
self.colors = collections.OrderedDict()
self.colors['default_fg'] = [ cp.get(cfg_sec, 'clr_default_fg'), 'Default fg' ]
diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py
@@ -846,6 +846,12 @@ def gui_frame_keypress(self, size, key):
self.view_titles.sort_note_list('alpha')
+ elif key == self.config.get_keybind('copy_note_text'):
+ if self.gui_body_get().__class__ != view_note.ViewNote:
+ return key
+
+ self.view_note.copy_note_text()
+
else:
return lb.keypress(size, key)
diff --git a/simplenote_cli/view_note.py b/simplenote_cli/view_note.py
@@ -5,6 +5,7 @@
import time, urwid
import utils
import re
+from clipboard import Clipboard
class ViewNote(urwid.ListBox):
@@ -19,6 +20,7 @@ def __init__(self, config, args):
self.note = self.ndb.get_note(self.key) if self.key else None
self.old_note = None
self.tabstop = int(self.config.get_config('tabstop'))
+ self.clipboard = Clipboard()
super(ViewNote, self).__init__(
urwid.SimpleFocusListWalker(self.get_note_content_as_list()))
@@ -194,6 +196,10 @@ def get_status_bar(self):
urwid.AttrMap(urwid.Pile([ pile_top, pile_bottom, pile_publish ]),
'status_bar')
+ def copy_note_text(self):
+ line_content = self.note['content'].split('\n')[self.focus_position]
+ self.clipboard.copy(line_content)
+
def keypress(self, size, key):
if key == self.config.get_keybind('tabstop2'):
self.tabstop = 2
@@ -214,4 +220,3 @@ def keypress(self, size, key):
return key
return None
-