From 64c756fe16ac76c8e64cabf78c63afe4132d283f Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Wed, 23 Jan 2013 13:35:03 -0800 Subject: [PATCH] add a script to dump most common commands from zhistory --- hist | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 hist diff --git a/hist b/hist new file mode 100755 index 0000000..34db25e --- /dev/null +++ b/hist @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby +# Project Name: None +# File / Folder: hist.rb +# File Language: ruby +# Copyright (C): 2006 heptadecagram +# First Author: heptadecagram +# First Created: 2006.03.13 20:14:58 +# Last Modifier: sjs +# Last Modified: 2010.02.11 +# +# now works w/ zsh and reports commands that account for at least 1% of the total + +command = {} +execution = {} +$total = 0 + +IO.foreach('/Users/sjs/config/zsh/zhistory') do |line| + line.chomp! =~ /^:\s\d+:\d+;((\S+).*)$/ + next if $1.nil? || $2.nil? + execution[$1] = 1 + execution[$1].to_i + command[$2] = 1 + command[$2].to_i + $total += 1 +end + +puts $total + +execution = execution.select {|a,b| b.to_f / $total > 0.01} +command = command.select {|a,b| b.to_f / $total > 0.01} + +Max_length = execution.sort_by {|a| a[0].length }.reverse[0][0].length + +def print_hash(hash) + sorted = hash.sort {|a,b| b[1] <=> a[1] } + sorted.each do |cmd,value| + printf " %#{Max_length}s: %3d(%.2f%%)\n", cmd, value, value.to_f / $total + end +end + + +puts "Executions:\n" +print_hash(execution) +puts "Commands:\n" +print_hash(command)