summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-18 22:49:42 -0400
committerGitHub <noreply@github.com>2019-03-18 22:49:42 -0400
commit2f24a8ad3eeb2fdf699d1e2a9d4f05429fe879c4 (patch)
treeb836270cf61175d1e4a434fd8cae08f0ffd998a2 /cmd2/utils.py
parent96d176cc3d8198913693a42c7dd983cf69a165bd (diff)
parent57dd827963491439e40eb5dfe20811c14ea757ff (diff)
downloadcmd2-git-2f24a8ad3eeb2fdf699d1e2a9d4f05429fe879c4.tar.gz
Merge branch 'master' into load_generate_transcript
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
index a8760a65..f3c29227 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -5,6 +5,7 @@
import collections
import os
import re
+import sys
import unicodedata
from typing import Any, Iterable, List, Optional, Union
@@ -88,6 +89,7 @@ def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]],
Node(val=4, left=None, right=7)
"""
T = collections.namedtuple(typename, field_names)
+ # noinspection PyProtectedMember,PyUnresolvedReferences
T.__new__.__defaults__ = (None,) * len(T._fields)
if isinstance(default_values, collections.Mapping):
prototype = T(**default_values)
@@ -350,3 +352,17 @@ def unquote_redirection_tokens(args: List[str]) -> None:
unquoted_arg = strip_quotes(arg)
if unquoted_arg in constants.REDIRECTION_TOKENS:
args[i] = unquoted_arg
+
+
+def find_editor() -> str:
+ """Find a reasonable editor to use by default for the system that the cmd2 application is running on."""
+ editor = os.environ.get('EDITOR')
+ if not editor:
+ if sys.platform[:3] == 'win':
+ editor = 'notepad'
+ else:
+ # Favor command-line editors first so we don't leave the terminal to edit
+ for editor in ['vim', 'vi', 'emacs', 'nano', 'pico', 'gedit', 'kate', 'subl', 'geany', 'atom']:
+ if which(editor):
+ break
+ return editor