From a2911149003213290d11aee3b7d62fa94f0c3678 Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Thu, 17 Dec 2015 12:52:42 +0100 Subject: [PATCH] Remove duplicated edit_cmd code Makes nano the default editor. Fixes #46 --- pubs/commands/init_cmd.py | 1 - pubs/config/__init__.py | 2 +- pubs/config/conf.py | 25 ------------------------- pubs/uis.py | 4 ++-- 4 files changed, 3 insertions(+), 29 deletions(-) diff --git a/pubs/commands/init_cmd.py b/pubs/commands/init_cmd.py index e20dd3e..df3de8c 100644 --- a/pubs/commands/init_cmd.py +++ b/pubs/commands/init_cmd.py @@ -42,7 +42,6 @@ def command(conf, args): conf['main']['pubsdir'] = pubsdir conf['main']['docsdir'] = docsdir conf['main']['open_cmd'] = config.default_open_cmd() - conf['main']['edit_cmd'] = config.default_edit_cmd() config.save_conf(conf) Repository(conf, create=True) diff --git a/pubs/config/__init__.py b/pubs/config/__init__.py index 5de91fb..ba7eaf2 100644 --- a/pubs/config/__init__.py +++ b/pubs/config/__init__.py @@ -1,2 +1,2 @@ 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 diff --git a/pubs/config/conf.py b/pubs/config/conf.py index 6c41e21..a512a90 100644 --- a/pubs/config/conf.py +++ b/pubs/config/conf.py @@ -75,28 +75,3 @@ def default_open_cmd(): return 'start' else: 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 diff --git a/pubs/uis.py b/pubs/uis.py index d4eab53..587db98 100644 --- a/pubs/uis.py +++ b/pubs/uis.py @@ -33,9 +33,9 @@ def _get_encoding(conf): def _get_local_editor(): """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():