LoginSignup
10
10

More than 5 years have passed since last update.

Zsh上で使用頻度の高いコマンド一覧を表示する

Last updated at Posted at 2012-10-11

zsh_history_sort.py
from collections import Counter, defaultdict
import sys

try:
    #FILENAME = "/Users/{hoge}/.zhistory"
    FILENAME = sys.argv[1]
except:
    print "USAGE: zsh_history_sort.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 (i, w) in enumerate(words):
        if i > 1: break;
        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 < 10: break
        print "%s%s: %d" % (INDENT, name, count)
        show(stat.children[name], indent + 1)

show(stat)

if i > 1: break;とかif count < 10: breakらへんを変えると深さと表示数を変更できます。
予想外に使用しているコマンドについては、短縮名を検討してみるといいかもです。

↓9割9分9厘下記ソースを使用しています。
元ネタ
show stat. of your git usage — Gist

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10