nncli

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

commit 0453cc7e4ff255fff3c2ca1fba323fe88266352c
parent 98f7e14c3e203a9777d3d88b55107f5cdf77d55a
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Tue, 26 Nov 2019 06:05:46 -0500

Smarten up the way we set defaults for cfg_editor

By default, we of course use the value specified in nncli.config. In the
event that isn't specified, we check $VISUAL, then $EDITOR. Failing
that, we use 'vim {fname} +{line}'

Diffstat:
Mdocs/source/configuration.rst | 4++--
Mnncli/config.py | 9+++++++--
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst @@ -147,8 +147,8 @@ General Options values ``{fname}`` and ``{line}`` can be used to specify respectively the file name and line number to pass to the command. - Optional. Default value: ``$EDITOR`` if defined in the user's - environment, else ``vim {fname} +{line}``. + Optional. Default value: ``$VISUAL`` or ``$EDITOR`` if defined in the + user's environment (preferring ``$VISUAL``), else ``vim {fname} +{line}``. .. confval:: cfg_pager diff --git a/nncli/config.py b/nncli/config.py @@ -37,8 +37,6 @@ 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' : os.environ['VISUAL'] \ - if 'VISUAL' in os.environ else 'vim {fname} +{line}', 'cfg_pager' : os.environ['PAGER'] \ if 'PAGER' in os.environ else 'less -c', 'cfg_max_logs' : '5', @@ -132,6 +130,13 @@ def __init__(self, custom_file=None): 'clr_help_descr_bg' : 'default' } + if 'VISUAL' in os.environ: + defaults['cfg_editor'] = os.environ['VISUAL'] + elif 'EDITOR' in os.environ: + defaults['cfg_editor'] = os.environ['EDITOR'] + else: + defaults['cfg_editor'] = 'vim {fname} +{line}' + parser = configparser.ConfigParser(defaults) if custom_file is not None: parser.read([custom_file])