Created
May 10, 2012 08:49
-
-
Save nishio/2651961 to your computer and use it in GitHub Desktop.
show stat. of your git usage
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
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