Skip to content

Instantly share code, notes, and snippets.

@frostidaho
Created November 11, 2015 02:56
Show Gist options
  • Save frostidaho/03983b457d8a0739c99b to your computer and use it in GitHub Desktop.
Save frostidaho/03983b457d8a0739c99b to your computer and use it in GitHub Desktop.
e.py partial rewrite
#!/usr/bin/env python
"""e.
Usage:
e.py [--wait] [PATHS ...]
e.py (-h | --help)
Options:
-h --help Show this screen.
-w --wait Wait.
"""
import subprocess
import os
from docopt import docopt
def trampify(path):
path = os.path.abspath(os.path.expandvars(os.path.expanduser(path)))
if path.startswith("/ssh:"):
return path
try:
with open(path, 'w+'):
pass # this creates the file if it doesn't exist
except:
path = "/sudo::" + path
return path
def desktop():
return os.environ.get('DISPLAY')
def wmctrl(args):
cmd = 'wmctrl ' + args
return subprocess.check_output(cmd.split())
def get_emacs_args(options):
eargs = ['-a']
if desktop() and not options['--wait']:
eargs.append('-n')
if options['PATHS']:
eargs.extend(trampify(x) for x in options['PATHS'])
return eargs
# ...
if __name__ == '__main__':
arguments = docopt(__doc__)
print(arguments)
print(get_emacs_args(arguments))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment