[PYTHON] Display a list of frequently used commands on Zsh

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)

You can change the depth and the number of displays by changing ʻif i> 1: break; or ʻif count <10: break. For commands that you use unexpectedly, you may want to consider abbreviated names.

↓ 90% 9 minutes 9 ㎘ The following sources are used. Former story show stat. of your git usage — Gist

Recommended Posts

Display a list of frequently used commands on Zsh
List of frequently used Linux commands
[Linux command] A memorandum of frequently used commands
A collection of commands frequently used in server management
[Anaconda3] Summary of frequently used commands
[Linux] Review of frequently used basic commands 2
Summary of frequently used commands of django (beginner)
Summary of frequently used commands in matplotlib
[Linux] List of Linux commands used in practice
Display a list of alphabets in Python 3
[Machine learning] List of frequently used packages
[Python/Django] Summary of frequently used commands (3) <Operation of PostgreSQL>
List of frequently used built-in functions and methods
[Python/Django] Summary of frequently used commands (2) <Installing packages>
Summary of frequently used commands (with petit commentary)
Frequently used tmux commands
Frequently used Linux commands
Frequently used Linux commands
Frequently used linux commands
Display of fractions (list)
Frequently used pip commands
[Linux] A list of Linux commands that beginners should know
Frequently used subpackages of SciPy
Frequently used commands in virtualenv
How to display a list of installable versions with pyenv
[Python] A memo of frequently used phrases (by myself) in Python scripts
8 Frequently Used Commands in Python Django
Linux Frequently Used Commands [Personal Memo]
[Golang] Notes on frequently used functions
Frequently used Linux commands (for beginners)
Commands often used on GAE / P
[Linux] Frequently used Linux commands (folder operation)
Generate a list of consecutive characters
Introduction of ls command lsix that can display a list of images
Make a list of "Houbunsha 70th Anniversary Campaign" on Selenium in Amazon
Paiza Skill Check List of Frequently Used D and C Ranks ~ Python ~
[Python/Django] Summary of frequently used commands (4) -Part 2- <Production operation: Amazon EC2 (Amazon Linux 2)>
[Linux] Command to get a list of commands executed in the past
[Python/Django] Summary of frequently used commands (4) -Part 1- <Production operation: Amazon EC2 (Amazon Linux 2)>
Display the graph of tensorBoard on jupyter
[python] Get a list of instance variables
String conversion of a list containing numbers
[Python] Get a list of folders only
[Linux] Review of commands for deploying on AWS
A memo of a tutorial on running python on heroku
[python] Create a list of various character types
A note on customizing the dict list class
Frequently used (personally) notes on the tar command
Make a copy of the list in Python
Simply display a line graph on Jupyter Notebook
Get a list of Qiita likes by scraping
Frequently used methods of Selenium and Beautiful Soup
Summary of frequently used Python arrays (for myself)
Selenium webdriver Summary of frequently used operation methods
A memorandum of commands, packages, terms, etc. used in linux (updated from time to time)