Remove duplicated edit_cmd code

Makes nano the default editor.

Fixes #46
main
Fabien Benureau 9 years ago
parent 854702488c
commit a291114900

@ -42,7 +42,6 @@ def command(conf, args):
conf['main']['pubsdir'] = pubsdir conf['main']['pubsdir'] = pubsdir
conf['main']['docsdir'] = docsdir conf['main']['docsdir'] = docsdir
conf['main']['open_cmd'] = config.default_open_cmd() conf['main']['open_cmd'] = config.default_open_cmd()
conf['main']['edit_cmd'] = config.default_edit_cmd()
config.save_conf(conf) config.save_conf(conf)
Repository(conf, create=True) Repository(conf, create=True)

@ -1,2 +1,2 @@
from .conf import get_confpath, load_default_conf, load_conf, save_conf, check_conf from .conf import get_confpath, load_default_conf, load_conf, save_conf, check_conf
from .conf import default_open_cmd, default_edit_cmd from .conf import default_open_cmd

@ -75,28 +75,3 @@ def default_open_cmd():
return 'start' return 'start'
else: else:
return None return None
def which(cmd):
try:
return shutil.which(cmd) # available in python 3.3
except AttributeError:
for path in ['.'] + os.environ["PATH"].split(os.pathsep):
filepath = os.path.join(path.strip('"'), cmd)
if os.path.isfile(path) and os.access(path, os.X_OK):
return filepath
return None
def default_edit_cmd():
"""Find an available editor"""
if 'EDITOR' in os.environ:
return os.environ['EDITOR']
elif platform.system() == 'Darwin' or 'Linux':
for editor in ['vim', 'nano', 'emacs', 'vi']:
if which(editor) is not None:
return editor
elif platform.system() == 'Windows':
return 'Notepad.exe | Out-Null' # wait for notepad to close
else:
return None

@ -33,9 +33,9 @@ def _get_encoding(conf):
def _get_local_editor(): def _get_local_editor():
"""Get the editor from environment variables. """Get the editor from environment variables.
Use vi as a default. Use nano as a default.
""" """
return os.environ.get('EDITOR', 'vi') return os.environ.get('EDITOR', 'nano')
def get_ui(): def get_ui():

Loading…
Cancel
Save