summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2014-10-09 09:55:21 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2014-10-09 09:55:21 -0500
commitbabe870e29c89a5b1aa54f83b6a6a5464adea2ed (patch)
tree14583cbee4b921f2edd4cdea95d1f8093513cadb
parentc042f8304bffd28c4600228c4a74a1bf418661bd (diff)
downloadcmd2-hg-babe870e29c89a5b1aa54f83b6a6a5464adea2ed.tar.gz
In the event "which" is not installed, return None
-rwxr-xr-xcmd2.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/cmd2.py b/cmd2.py
index a110932..53b7040 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -104,6 +104,12 @@ def _attr_get_(obj, attr):
return getattr(obj, attr)
except AttributeError:
return None
+
+def _which(editor):
+ try:
+ return subprocess.Popen(['which', editor], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
+ except OSError:
+ return None
optparse.Values.get = _attr_get_
@@ -421,7 +427,7 @@ class Cmd(cmd.Cmd):
editor = 'notepad'
else:
for editor in ['gedit', 'kate', 'vim', 'vi', 'emacs', 'nano', 'pico']:
- if subprocess.Popen(['which', editor], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]:
+ if _which(editor):
break
colorcodes = {'bold':{True:'\x1b[1m',False:'\x1b[22m'},