|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
import os
|
|
|
|
|
import platform
|
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
|
|
import configobj
|
|
|
|
|
import validate
|
|
|
|
@ -54,3 +56,37 @@ def save_conf(conf, path=None):
|
|
|
|
|
path = get_confpath(verify=False)
|
|
|
|
|
with open(path, 'wb') as f:
|
|
|
|
|
conf.write(outfile=f)
|
|
|
|
|
|
|
|
|
|
def default_open_cmd():
|
|
|
|
|
"""Chooses the default command to open documents"""
|
|
|
|
|
if platform.system() == 'Darwin':
|
|
|
|
|
return 'open'
|
|
|
|
|
elif platform.system() == 'Linux':
|
|
|
|
|
return 'xdg-open'
|
|
|
|
|
elif platform.system() == 'Windows':
|
|
|
|
|
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
|
|
|
|
|