Last active
December 31, 2015 06:38
-
-
Save r00k/7948384 to your computer and use it in GitHub Desktop.
Parses zsh_history. It calculates the commands that you spend the most time typing (length of command * frequency of typing it) and returns the top-ten most costly commands with their frequencies.
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
(ns noodle.core) | |
(defn history-line->command | |
"Returns the command from a zsh_history-style line" | |
[line] | |
(nth (clojure.string/split line #"\s+") 2)) | |
(defn weight | |
"Returns a number representing how much time you've spent typing a command" | |
[command invocation-count] | |
(* invocation-count (count command))) | |
(defn sort-by-weight | |
[m] | |
(reverse (sort-by (partial apply weight) (vec m)))) | |
(defn counts | |
[commands] | |
(frequencies commands)) | |
(defn format-history-map | |
[history-map] | |
(letfn [(format-one [[command weight]] | |
(format "%s: %d\n" command weight))] | |
(clojure.string/join (map format-one history-map)))) | |
(defn format-history-lines | |
[history-lines] | |
((comp | |
format-history-map | |
(partial take 10) | |
sort-by-weight | |
counts | |
(partial map history-line->command)) | |
history-lines)) | |
(defn main | |
"Prints the top 10 most-costly commands and their frequencies" | |
[] | |
(-> | |
*in* | |
java.io.BufferedReader. | |
line-seq | |
format-history-lines | |
println)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment