Skip to content

Instantly share code, notes, and snippets.

@teki
Created November 29, 2016 23:11
Show Gist options
  • Save teki/16f96b99aa163358926885ed329ecfa8 to your computer and use it in GitHub Desktop.
Save teki/16f96b99aa163358926885ed329ecfa8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
import json
import os
import shutil
import sys
import subprocess
import urllib2
PACKAGES_URL = "https://raw.githubusercontent.com/alcatraz/alcatraz-packages/master/packages.json"
THEME_PATH = os.path.join(os.environ['HOME'], "Library/Developer/Xcode/UserData/FontAndColorThemes")
def get_packages():
return json.load(urllib2.urlopen(PACKAGES_URL))
def install_theme(scheme):
if not os.path.isdir(THEME_PATH):
os.mkdir(THEME_PATH)
pwd = os.curdir
os.chdir(THEME_PATH)
subprocess.call("curl -O " + scheme[u'url'], shell=True)
os.chdir(pwd)
def delete_theme(scheme):
fname = os.path.basename(scheme[u'url'])
scheme_path = os.path.join(THEME_PATH, fname)
if os.path.exists(scheme_path):
os.remove(scheme_path)
def is_installed(scheme):
fname = os.path.basename(scheme[u'url'])
return os.path.exists(os.path.join(THEME_PATH, fname))
packages = get_packages()
color_schemes = packages[u'packages'][u'color_schemes']
if len(sys.argv) == 2:
act_scheme = color_schemes[int(sys.argv[1])]
do_delete = is_installed(act_scheme)
txt_prefix = do_delete and "delete" or "install"
print(txt_prefix + ' ' + act_scheme[u'name'] + ' N/y:',)
if raw_input().lower() == 'y':
if do_delete:
delete_theme(act_scheme)
else:
install_theme(act_scheme)
exit(0)
for i, act_scheme in enumerate(color_schemes):
installed = is_installed(act_scheme)
print("{} {:3d} {}".format(installed and u'*' or u' ', i, act_scheme[u'name']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment