Skip to content

Instantly share code, notes, and snippets.

@nishio
Created May 10, 2012 08:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nishio/2651961 to your computer and use it in GitHub Desktop.
Save nishio/2651961 to your computer and use it in GitHub Desktop.
show stat. of your git usage
from collections import Counter, defaultdict
import sys
try:
#FILENAME = "/Users/nishio/.oh-my-zsh/.zhistory"
FILENAME = sys.argv[1]
except:
print "USAGE: git_stat.py <your_history_file>"
sys.exit(1)
class Stat(object):
def __init__(self):
self.counter = Counter()
self.children = defaultdict(Stat)
stat = Stat()
fi = file(FILENAME)
for line in fi:
line = line.strip()
if ";" in line:
line = line.split(";")[1]
words = line.split()
s = stat
for w in words:
s.counter[w] += 1
s = s.children[w]
def show(stat, indent=0):
INDENT = " " * indent
for name, count in stat.counter.most_common():
if count < 2: break
print "%s%s: %d" % (INDENT, name, count)
show(stat.children[name], indent + 1)
git = stat.children["git"]
show(git)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment