-
-
Save frostidaho/03983b457d8a0739c99b to your computer and use it in GitHub Desktop.
e.py partial rewrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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