From a1aeec3e1a9b38e98e920a0cffa2e35af541ec43 Mon Sep 17 00:00:00 2001 From: Peyton Walters Date: Sun, 15 Oct 2017 18:43:55 -0400 Subject: [PATCH 1/2] Added title searching to sncli --- simplenote_cli/sncli.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py index a0fa13f..5ac695b 100644 --- a/simplenote_cli/sncli.py +++ b/simplenote_cli/sncli.py @@ -1386,10 +1386,33 @@ def sncli_start(sync=sync, verbose=verbose, config=config): elif args[0] == 'edit': + sn = 0 + if not key: - usage() + if not title: + usage() + else: + sn = sncli_start() + note_list, match_regex, all_notes_cnt = \ + sn.ndb.filter_notes( + title, + search_mode='gstyle', + sort_mode=sn.config.get_config('sort_mode')) + if len(note_list) == 1: + key = note_list[0].key + elif len(note_list) == 0: + print(''' +No notes could be found containing that title string. +''') + sys.exit(0) + else: + print(''' +There were too many notes containing that title string. Please be more specific. +''') + sys.exit(0) - sn = sncli_start() + if sn == 0: + sn = sncli_start() sn.cli_note_edit(key) elif args[0] == 'trash' or args[0] == 'untrash': From bee50760f6914286ad8c32f40cef397b8c8b4a4b Mon Sep 17 00:00:00 2001 From: Peyton Walters Date: Sun, 15 Oct 2017 20:55:38 -0400 Subject: [PATCH 2/2] Added get_key_from_title def and added allowed editing, trashing, marking down, and pinning based on title --- simplenote_cli/sncli.py | 73 ++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py index 5ac695b..0b85721 100644 --- a/simplenote_cli/sncli.py +++ b/simplenote_cli/sncli.py @@ -128,7 +128,7 @@ def exec_diff_on_note(self, note, old_note): out = temp.tempfile_create(None, tempdir=self.tempdir) try: - subprocess.call(diff + ' ' + + subprocess.call(diff + ' ' + temp.tempfile_name(ltf) + ' ' + temp.tempfile_name(otf) + ' > ' + temp.tempfile_name(out), @@ -1253,6 +1253,26 @@ def cli_note_tags_rm(self, key, rm_tags): tags = ','.join(tag_list) self.cli_note_tags_set(key, tags) + def get_key_from_title(self, title): + + note_list, match_regex, all_notes_cnt = \ + self.ndb.filter_notes( + title, + search_mode='gstyle', + sort_mode=self.config.get_config('sort_mode')) + if len(note_list) == 1: + return note_list[0].key + elif len(note_list) == 0: + print(''' +No notes could be found containing that title string. +''') + sys.exit(0) + else: + print(''' +There were too many notes containing that title string. Please be more specific. +''') + sys.exit(0) + def SIGINT_handler(signum, frame): print('\nSignal caught, bye!') sys.exit(1) @@ -1393,50 +1413,51 @@ def sncli_start(sync=sync, verbose=verbose, config=config): usage() else: sn = sncli_start() - note_list, match_regex, all_notes_cnt = \ - sn.ndb.filter_notes( - title, - search_mode='gstyle', - sort_mode=sn.config.get_config('sort_mode')) - if len(note_list) == 1: - key = note_list[0].key - elif len(note_list) == 0: - print(''' -No notes could be found containing that title string. -''') - sys.exit(0) - else: - print(''' -There were too many notes containing that title string. Please be more specific. -''') - sys.exit(0) + key = sn.get_key_from_title(title) - if sn == 0: - sn = sncli_start() + sn = sncli_start() if sn == 0 else sn sn.cli_note_edit(key) elif args[0] == 'trash' or args[0] == 'untrash': + sn = 0 + if not key: - usage() + if not title: + usage() + else: + sn = sncli_start() + key = sn.get_key_from_title(title) - sn = sncli_start() + sn = sncli_start() if sn == 0 else sn sn.cli_note_trash(key, 1 if args[0] == 'trash' else 0) elif args[0] == 'pin' or args[0] == 'unpin': + sn = 0 + if not key: - usage() + if not title: + usage() + else: + sn = sncli_start() + key = sn.get_key_from_title(title) - sn = sncli_start() + sn = sncli_start() if sn == 0 else sn sn.cli_note_pin(key, 1 if args[0] == 'pin' else 0) elif args[0] == 'markdown' or args[0] == 'unmarkdown': + sn = 0 + if not key: - usage() + if not title: + usage() + else: + sn = sncli_start() + key = sn.get_key_from_title(title) - sn = sncli_start() + sn = sncli_start() if sn == 0 else sn sn.cli_note_markdown(key, 1 if args[0] == 'markdown' else 0) # Tag API