nncli

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

commit 660bb2e9c82a44b5bc2916cdfc2dc7d189d32071
parent 731f07a364a00176de88b26bc9684ce5b11c6635
Author: Eric Davis <edavis@insanum.com>
Date:   Fri, 11 Jul 2014 17:05:06 -0700

now a single keybind for trash, pin, and markdown which acts as a toggle

Diffstat:
Mconfig.py | 10++--------
Msncli.py | 45+++++++++++++++++++++++++--------------------
2 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/config.py b/config.py @@ -34,8 +34,6 @@ def __init__(self): 'kb_bottom' : 'G', 'kb_top' : 'g', 'kb_status' : 's', - 'kb_trash_note' : 'T', - 'kb_untrash_note' : 'U', 'kb_create_note' : 'C', 'kb_edit_note' : 'e', 'kb_view_note' : 'enter', @@ -52,10 +50,9 @@ def __init__(self): 'kb_clear_search' : 'A', 'kb_sort_date' : 'd', 'kb_sort_alpha' : 'a', + 'kb_note_trash' : 'T', 'kb_note_pin' : 'p', - 'kb_note_unpin' : 'P', 'kb_note_markdown' : 'm', - 'kb_note_unmarkdown' : 'M', 'kb_note_tags' : 't', 'clr_default_fg' : 'default', @@ -141,8 +138,6 @@ def __init__(self): self.keybinds['status'] = [ cp.get(cfg_sec, 'kb_status'), [ 'common' ], 'Toggle status bar' ] self.keybinds['view_log'] = [ cp.get(cfg_sec, 'kb_view_log'), [ 'common' ], 'View log' ] self.keybinds['create_note'] = [ cp.get(cfg_sec, 'kb_create_note'), [ 'titles' ], 'Create a new note' ] - self.keybinds['trash_note'] = [ cp.get(cfg_sec, 'kb_trash_note'), [ 'titles', 'notes' ], 'Trash a note' ] - self.keybinds['untrash_note'] = [ cp.get(cfg_sec, 'kb_untrash_note'), [ 'titles', 'notes' ], 'Untrash a note' ] self.keybinds['edit_note'] = [ cp.get(cfg_sec, 'kb_edit_note'), [ 'titles', 'notes' ], 'Edit note' ] self.keybinds['view_note'] = [ cp.get(cfg_sec, 'kb_view_note'), [ 'titles' ], 'View note' ] self.keybinds['view_note_ext'] = [ cp.get(cfg_sec, 'kb_view_note_ext'), [ 'titles', 'notes' ], 'View note with pager' ] @@ -157,10 +152,9 @@ def __init__(self): self.keybinds['clear_search'] = [ cp.get(cfg_sec, 'kb_clear_search'), [ 'titles' ], 'Show all notes' ] self.keybinds['sort_date'] = [ cp.get(cfg_sec, 'kb_sort_date'), [ 'titles' ], 'Sort notes by date' ] self.keybinds['sort_alpha'] = [ cp.get(cfg_sec, 'kb_sort_alpha'), [ 'titles' ], 'Sort notes by alpha' ] + self.keybinds['note_trash'] = [ cp.get(cfg_sec, 'kb_note_trash'), [ 'titles', 'notes' ], 'Trash a note' ] self.keybinds['note_pin'] = [ cp.get(cfg_sec, 'kb_note_pin'), [ 'titles', 'notes' ], 'Pin note' ] - self.keybinds['note_unpin'] = [ cp.get(cfg_sec, 'kb_note_unpin'), [ 'titles', 'notes' ], 'Unpin note' ] self.keybinds['note_markdown'] = [ cp.get(cfg_sec, 'kb_note_markdown'), [ 'titles', 'notes' ], 'Flag note as markdown' ] - self.keybinds['note_unmarkdown'] = [ cp.get(cfg_sec, 'kb_note_unmarkdown'), [ 'titles', 'notes' ], 'Unflag note as markdown' ] self.keybinds['note_tags'] = [ cp.get(cfg_sec, 'kb_note_tags'), [ 'titles', 'notes' ], 'Edit note tags' ] self.colors = collections.OrderedDict() diff --git a/sncli.py b/sncli.py @@ -339,8 +339,7 @@ def gui_frame_keypress(self, size, key): else: self.status_bar = self.config.get_config('status_bar') - elif key == self.config.get_keybind('trash_note') or \ - key == self.config.get_keybind('untrash_note'): + elif key == self.config.get_keybind('note_trash'): if self.gui_body_get().__class__ != view_titles.ViewTitles and \ self.gui_body_get().__class__ != view_note.ViewNote: return key @@ -353,7 +352,7 @@ def gui_frame_keypress(self, size, key): note = lb.note self.ndb.set_note_deleted(note['key'], - 1 if key == self.config.get_keybind('trash_note') else 0) + 1 if not note['deleted'] else 0) elif key == self.config.get_keybind('create_note'): if self.gui_body_get().__class__ != view_titles.ViewTitles: @@ -536,8 +535,7 @@ def gui_frame_keypress(self, size, key): self.gui_footer_focus_input() self.master_frame.keypress = self.gui_footer_input_get().keypress - elif key == self.config.get_keybind('note_pin') or \ - key == self.config.get_keybind('note_unpin'): + elif key == self.config.get_keybind('note_pin'): if self.gui_body_get().__class__ != view_titles.ViewTitles and \ self.gui_body_get().__class__ != view_note.ViewNote: return key @@ -549,14 +547,17 @@ def gui_frame_keypress(self, size, key): else: # self.gui_body_get().__class__ == view_note.ViewNote: note = lb.note - self.ndb.set_note_pinned(note['key'], - 1 if key == self.config.get_keybind('note_pin') else 0) + pin = 1 + if 'systemtags' in note: + if 'pinned' in note['systemtags']: pin = 0 + else: pin = 1 + + self.ndb.set_note_pinned(note['key'], pin) if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title(None) - elif key == self.config.get_keybind('note_markdown') or \ - key == self.config.get_keybind('note_unmarkdown'): + elif key == self.config.get_keybind('note_markdown'): if self.gui_body_get().__class__ != view_titles.ViewTitles and \ self.gui_body_get().__class__ != view_note.ViewNote: return key @@ -568,8 +569,12 @@ def gui_frame_keypress(self, size, key): else: # self.gui_body_get().__class__ == view_note.ViewNote: note = lb.note - self.ndb.set_note_markdown(note['key'], - 1 if key == self.config.get_keybind('note_markdown') else 0) + md = 1 + if 'systemtags' in note: + if 'markdown' in note['systemtags']: md = 0 + else: md = 1 + + self.ndb.set_note_markdown(note['key'], md) if self.gui_body_get().__class__ == view_titles.ViewTitles: lb.update_note_title(None) @@ -853,34 +858,34 @@ def cli_edit_note(self, key): temp.tempfile_delete(tf) - def cli_trash_untrash_note(self, key, trash): + def cli_note_trash(self, key, trash): note = self.ndb.get_note(key) if not note: self.log(u'ERROR: Key does not exist') return - self.ndb.set_note_deleted(note['key'], 1 if trash else 0) + self.ndb.set_note_deleted(key, trash) self.sync_notes() - def cli_pin_unpin_note(self, key, pin): + def cli_note_pin(self, key, pin): note = self.ndb.get_note(key) if not note: self.log(u'ERROR: Key does not exist') return - self.ndb.set_note_pinned(note['key'], 1 if pin else 0) + self.ndb.set_note_pinned(key, pin) self.sync_notes() - def cli_markdown_unmarkdown_note(self, key, markdown): + def cli_note_markdown(self, key, markdown): note = self.ndb.get_note(key) if not note: self.log(u'ERROR: Key does not exist') return - self.ndb.set_note_markdown(note['key'], 1 if markdown else 0) + self.ndb.set_note_markdown(key, markdown) self.sync_notes() @@ -977,7 +982,7 @@ def sncli_start(sync): usage() sn = sncli_start(sync) - sn.cli_trash_untrash_note(key, 1 if args[0] == 'trash' else 0) + sn.cli_note_trash(key, 1 if args[0] == 'trash' else 0) elif args[0] == 'pin' or args[0] == 'unpin': @@ -985,7 +990,7 @@ def sncli_start(sync): usage() sn = sncli_start(sync) - sn.cli_pin_unpin_note(key, 1 if args[0] == 'pin' else 0) + sn.cli_note_pin(key, 1 if args[0] == 'pin' else 0) elif args[0] == 'md' or args[0] == 'unmd': @@ -993,7 +998,7 @@ def sncli_start(sync): usage() sn = sncli_start(sync) - sn.cli_markdown_unmarkdown_note(key, 1 if args[0] == 'md' else 0) + sn.cli_note_markdown(key, 1 if args[0] == 'md' else 0) else: usage()