nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit 4970b0c88dd9e48542ccbe173cbbe7b7a2bdc516
parent cb9967ab5c6edb5543459db57352beee3d56464d
Author: Eric Davis <edavis@insanum.com>
Date:   Sun,  6 Jul 2014 18:20:22 -0700

new keybind command for piping note contents to a shell command

Diffstat:
Mconfig.py | 2++
Msncli.py | 31++++++++++++++++++++++++++++++-
2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/config.py b/config.py @@ -39,6 +39,7 @@ def __init__(self): 'kb_edit_note' : 'e', 'kb_view_note' : 'enter', 'kb_view_note_ext' : 'meta enter', + 'kb_pipe_note' : '|', 'kb_view_next_note' : 'J', 'kb_view_prev_note' : 'K', 'kb_view_log' : 'l', @@ -141,6 +142,7 @@ def __init__(self): 'edit_note' : [ cp.get(cfg_sec, 'kb_edit_note'), [ 'titles' ], 'Edit note' ], 'view_note' : [ cp.get(cfg_sec, 'kb_view_note'), [ 'titles' ], 'View note' ], 'view_note_ext' : [ cp.get(cfg_sec, 'kb_view_note_ext'), [ 'titles' ], 'View note with pager' ], + 'pipe_note' : [ cp.get(cfg_sec, 'kb_pipe_note'), [ 'titles' ], 'Pipe note contents' ], 'view_next_note' : [ cp.get(cfg_sec, 'kb_view_next_note'), [ 'notes' ], 'View next note' ], 'view_prev_note' : [ cp.get(cfg_sec, 'kb_view_prev_note'), [ 'notes' ], 'View previous note' ], 'tabstop2' : [ cp.get(cfg_sec, 'kb_tabstop2'), [ 'notes' ], 'View with tabstop=2' ], diff --git a/sncli.py b/sncli.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 -import os, sys, re, signal, time, datetime, md5, logging +import os, sys, re, signal, time, datetime, shlex, md5, logging import subprocess, thread, threading import copy, json, urwid, datetime import view_titles, view_note, view_help, view_log, user_input @@ -239,6 +239,21 @@ def tags_input(self, tags): self.view_titles.note_list[self.view_titles.focus_position].note['key'], tags) self.view_titles.update_note_title(None) + def pipe_input(self, cmd): + self.footer_clear() + self.body_focus() + self.master_frame.keypress = self.frame_keypress + if cmd != None: + note = self.view_titles.note_list[self.view_titles.focus_position].note + args = shlex.split(cmd) + try: + pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True) + pipe.communicate(note['content']) + pipe.stdin.close() + pipe.wait() + except OSError, e: + self.status_message_set(u'Pipe error: ' + str(e)) + def frame_keypress(self, size, key): lb = self.body_get() @@ -414,6 +429,20 @@ def frame_keypress(self, size, key): lb.update_note_title(None) temp.tempfile_delete(tf) + elif key == self.config.get_keybind('pipe_note'): + # only when viewing the note list + if self.body_get().__class__ == view_titles.ViewTitles: + note = lb.note_list[lb.focus_position].note + self.status_message_cancel() + self.footer_set( + urwid.AttrMap( + user_input.UserInput(self.config, + key, '', + self.pipe_input), + 'search_bar')) + self.footer_focus() + self.master_frame.keypress = self.footer_get().keypress + elif key == self.config.get_keybind('view_next_note'): # only when viewing the note content if self.body_get().__class__ == view_note.ViewNote: