Skip to content

Instantly share code, notes, and snippets.

@smison
Created August 19, 2014 06:14
Show Gist options
  • Save smison/5998090d5c922b513922 to your computer and use it in GitHub Desktop.
Save smison/5998090d5c922b513922 to your computer and use it in GitHub Desktop.
history_counter.rb
#! /usr/local/bin/ruby
require 'kconv'
LENGTH = 3
COUNT = 5
ines = File.read('/home/<USERNAME>/.bash_history').toutf8.split("\n")
lines_uq = lines.uniq
rethash = Hash.new
lines_uq.each do |line|
rethash[line] = lines.count(line)
end
retmats = rethash.select{|key, value| (key.length >= LENGTH) & (value > COUNT)}
.sort{|a, b| a.last <=> b.last}
maxlength = retmats.map{|mat| mat.last.to_s.length}.max
retmats.each do |retmat|
puts ("*" * (maxlength - retmat.last.to_s.length)) + "#{retmat.last}: #{retmat.first}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment