Shell History in Ruby

Add a reply

Posted by pjb3 701 days ago:
Print out the 10 most commonly used commands from your shell history, with the number. Here's the best I've done so far,:

~ $ history | ruby -e '$<.inject(Hash.new(0)){|h,l| h[l.split[1]] += 1; h}.sort{|a,b| b[1]<=>a[1]}[0..9].each{|k,v| puts "#{v} #{k}"}'
138 cd
55 ls
40 merb
31 mate
29 cat
19 mv
17 httperf
15 rm
14 ant
14 rake

Add a reply