Skip to content

Instantly share code, notes, and snippets.

@TonyPythoneer
Last active April 1, 2017 06:57
Show Gist options
  • Save TonyPythoneer/09c2444168f1e44155de954a5829c9e2 to your computer and use it in GitHub Desktop.
Save TonyPythoneer/09c2444168f1e44155de954a5829c9e2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# chmod u+x backup_vscode_extensions.py
# example:
# >> ./backup_vscode_extensions backup
# >>./backup_vscode_extensions install extensions.txt
from subprocess import check_output, call
from sys import argv
from functools import wraps
def log(f):
@wraps(f)
def wrapper(*args, **kwargs):
print '[log] Trigger ' + f.__name__
return f(*args, **kwargs)
return wrapper
@log
def backup():
print
extensions = check_output(['code', '--list-extensions'])
with open('extensions.txt', 'wb') as f:
f.write(extensions)
@log
def install(filename):
with open(filename, 'rb') as f:
for line in f:
extension = line.replace('\n', '')
call(['code', '--install-extension', extension])
def main():
if len(argv) <= 1:
return
action = argv[1]
if action == backup.__name__:
backup()
elif action == install.__name__:
if len(argv) >= 3:
filename = argv[2]
install(filename)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment