From ef8ac022b1338e13aa1d41c79f3b0b10c31b05e6 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 4 Jun 2012 19:59:12 +0200 Subject: [PATCH] compute history stats, simple version --- src/history_stats_0.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/history_stats_0.py diff --git a/src/history_stats_0.py b/src/history_stats_0.py new file mode 100644 index 0000000..e3a896f --- /dev/null +++ b/src/history_stats_0.py @@ -0,0 +1,28 @@ +#!/bin/env python3 + +import os + +if __name__=="__main__": + + history = {} + hist_conf = os.path.expanduser("~/.bash_history") + with open(hist_conf) as hfile: + for line in hfile: + if line[0] != "#": + items = line.split() + if len(items) > 0: + cmd = line.split()[0] + + if cmd in history: + history[cmd] += 1 + else: + history[cmd] = 1 + + stats = [] + for cmd in history: + stats.append( (history[cmd],cmd) ) + + sort = sorted(stats, reverse=True) + + for count,cmd in sort[0:20]: + print(count,"\t",cmd)