Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis cellularmitosis/README.md
Last active Oct 17, 2019

Embed
What would you like to do?
ls-repos.py: a quick hack to list my github repos from the command line.

Blog 2019/2/1

<- previous | index | next ->

ls-repos.py: list your github repos from the command-line

This script gives you a convenient way to access your list of repos. Useful for piping the output into grep, etc.

#!/usr/bin/env python
# ls-repos.py: a simple script to list your github repos.
# usage:
# ./ls-repos.py
# list all repos in the form <org>/<repo>
# ./ls-repos.py <org>
# list all repos for an org in the form <repo>
# export LSREPOS_USERNAME and LSREPOS_PASSWORD to avoid prompts.
import getpass
import os
import sys
try:
import github
except:
sys.stderr.write("Error: github module not found.\n")
sys.stderr.write("Please 'sudo pip install PyGithub'.\n")
sys.exit(1)
orgname_filter = None
if len(sys.argv) > 1:
orgname_filter = sys.argv[-1]
if "LSREPOS_USERNAME" in os.environ:
username = os.environ["LSREPOS_USERNAME"]
else:
username = raw_input("github username: ")
if "LSREPOS_PASSWORD" in os.environ:
password = os.environ["LSREPOS_PASSWORD"]
else:
password = getpass.getpass("github password: ")
g = github.Github(username, password)
user = g.get_user()
repos = list(user.get_repos())
for repo in repos:
fullname = repo.full_name
(orgname, reponame) = fullname.split('/')
if orgname_filter:
if orgname == orgname_filter:
print reponame
else:
print fullname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.