Last active
August 29, 2015 14:08
-
-
Save jefftriplett/aaefa7d0fd7c5736b916 to your computer and use it in GitHub Desktop.
Dump your homebrew config into a cider (https://github.com/msanders/cider) compatible json format
This file contains hidden or 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
import click | |
import json | |
import subprocess | |
def run_command(cmd, as_list=True): | |
try: | |
output = subprocess.check_output( | |
cmd, | |
stderr=subprocess.STDOUT, | |
shell=True | |
) | |
except Exception as e: | |
print 'Warning: {0}'.format(e) | |
return [] | |
if as_list: | |
lines = [line for line in output.split('\n') if line] | |
return lines | |
else: | |
return output | |
def get_casks(): | |
casks = run_command('brew cask list') | |
return casks or [] | |
def get_formulas(): | |
formulas = run_command('brew list') | |
return formulas or [] | |
def get_taps(): | |
taps = run_command('brew tap') | |
return taps or [] | |
@click.command() | |
@click.option('--indent', default=4, help='JSON indentation length.') | |
def main(indent): | |
doc = { | |
'casks': get_casks(), | |
'formulas': get_formulas(), | |
'taps': get_taps(), | |
} | |
print json.dumps(doc, indent=indent) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment