Created
October 27, 2009 14:21
-
-
Save jkramer/219594 to your computer and use it in GitHub Desktop.
This file contains 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
-- ZChart | |
-- Find the 10 most popular commands from your ZSH history and build a Google | |
-- Chart from it. Prints the charts URL to stdout and saves it as PNG in | |
-- "history.png". | |
import System.IO | |
import System.Environment | |
import Data.List | |
import Data.Char | |
import Control.Arrow | |
import Graphics.Google.Chart | |
import Data.ByteString.Char8 (unpack) | |
import Network.Download | |
main = getEnv "HISTFILE" >>= readFile >>= googleChart . topTen . parse | |
parse = map (takeWhile (not . isSpace) . dropWhile (not . isAlpha)) . lines | |
topTen full = take 10 $ sortByUsage $ uniqC full | |
where | |
uniqC = map (id &&& count) . nub | |
count = length . flip elemIndices full | |
sortByUsage = sortBy (flip (compare . snd) . snd) | |
googleChart values = | |
putStrLn uri >> openURI uri >>= writeFile "history.png" . check | |
where | |
check = either error unpack | |
uri = chartURL | |
$ setSize 600 400 | |
$ setTitle "ZSH History Top 10" | |
$ setData (encodeDataExtended [map snd values]) | |
$ setLabels (map fst values) | |
$ newPieChart Pie2D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment