nncli

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

commit b350be316a8a684ece68ac6daddcc68d77c5742a
parent e8e17905975358f459c6223167c17e523849cddf
Author: Samuel Walladge <samuel@swalladge.id.au>
Date:   Wed,  1 Nov 2017 12:01:43 +1030

complete implementation of opening editor at line

- fully backwards compatible

Diffstat:
Msimplenote_cli/config.py | 2+-
Msimplenote_cli/sncli.py | 19++++++++++++++-----
2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/simplenote_cli/config.py b/simplenote_cli/config.py @@ -20,7 +20,7 @@ def __init__(self, custom_file=None): 'cfg_format_strftime' : '%Y/%m/%d', 'cfg_format_note_title' : '[%D] %F %-N %T', 'cfg_status_bar' : 'yes', - 'cfg_editor' : 'vim {fname} +{line}', + 'cfg_editor' : os.environ['EDITOR'] if 'EDITOR' in os.environ else 'vim {fname} +{line}', 'cfg_pager' : 'less -c', 'cfg_diff' : 'diff -b -U10', 'cfg_max_logs' : '5', diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -65,8 +65,6 @@ def sync_notes(self): def get_editor(self): editor = self.config.get_config('editor') - if 'EDITOR' in os.environ: - editor = os.environ['EDITOR'] if not editor: self.log('No editor configured!') return None @@ -96,9 +94,20 @@ def exec_cmd_on_note(self, note, cmd=None, raw=False): return None tf = temp.tempfile_create(note if note else None, raw=raw, tempdir=self.tempdir) - lb = self.gui_body_get() - cmd_list = [c.format(line=lb.focus_position + 1, fname=temp.tempfile_name(tf)) for c in cmd.split(" ")] - self.log("EXECUTING {}".format(cmd_list)) + fname = temp.tempfile_name(tf) + + subs = { + 'fname': fname, + 'line': self.gui_body_get().focus_position + 1, + } + cmd_list = [c.format(**subs) for c in shlex.split(cmd)] + + # if the filename wasn't able to be subbed, append it + # this makes it fully backwards compatible with previous configs + if '{fname}' not in cmd: + cmd_list.append(fname) + + self.log("EXECUTING: {}".format(cmd_list)) try: subprocess.check_call(cmd_list)