Moved editor to a helper function.

This commit is contained in:
Michael Lazar
2015-03-27 23:21:26 -07:00
parent 32fd689544
commit 9ddce7fd35
2 changed files with 66 additions and 63 deletions

View File

@@ -9,6 +9,20 @@ from . import config
__all__ = ['open_browser', 'clean', 'wrap_text', 'strip_textpad',
'strip_subreddit_url', 'humanize_timestamp']
def open_editor(filename):
"""
Open the given file using the system's default editor.
"""
editors = [os.getenv('RTV_EDITOR'), os.getenv('EDITOR'), 'nano', 'vi']
for program in editors:
if program:
try:
subprocess.Popen([program, filename]).wait()
break
except OSError:
pass
def open_browser(url):
"""
Call webbrowser.open_new_tab(url) and redirect stdout/stderr to devnull.