Create a gist now

Instantly share code, notes, and snippets.

Clone or update a user's gists locally
#!/bin/bash
curl -ks https://gist.githubusercontent.com/nicerobot/1622504/raw/gist-backup.py | USER=${USER} python3
#!/usr/bin/env python3
# Clone or update all a user's gists
# curl -ks https://gist.githubusercontent.com/nicerobot/1622504/raw/backup.sh | bash
# curl -ks https://gist.githubusercontent.com/nicerobot/1622504/raw/backup.sh | USER=nicerobot bash
import json
from subprocess import call
from urllib.request import urlopen
import os
USER = os.environ['USER']
with urlopen('https://api.github.com/users/'+USER+'/gists') as u:
startd = os.getcwd()
for gist in json.loads(u.read().decode('utf8')):
gistd = os.path.basename(gist['html_url'])
pull = gist['git_pull_url']
print(pull)
if os.path.isdir(gistd):
os.chdir(gistd)
call(['git', 'pull', pull])
os.chdir(startd)
else:
call(['git', 'clone', pull])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment