Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to operate based on title #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions simplenote_cli/sncli.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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),
Expand Down Expand Up @@ -1263,6 +1263,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)
Expand Down Expand Up @@ -1396,34 +1416,58 @@ 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()
key = sn.get_key_from_title(title)

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
Expand Down