Skip to content

Instantly share code, notes, and snippets.

@xiejiangzhi
Created August 16, 2015 08:52
Show Gist options
  • Save xiejiangzhi/fc600fb85ceef05ea1b5 to your computer and use it in GitHub Desktop.
Save xiejiangzhi/fc600fb85ceef05ea1b5 to your computer and use it in GitHub Desktop.
统计CLI下输入最多的工具名与输入的命令
#! /usr/bin/env ruby
# Tool top 10
# git 100
# vim 49
# xxx 21
#
# Action top 10
# git checkout master 231
# vim index.html 192
# cd .. 133
#
commands = `cat #{Dir.home}/.bash_history`.lines
action_counter = Hash.new(0)
tool_counter = Hash.new(0)
commands.each do |line|
cmd = line.split.first
tool_counter[cmd] += 1
action_counter[line] += 1
end
puts "Tool top 10:"
tool_counter.to_a.sort_by(&:last).reverse[0..10].each do |cmd, total|
puts " #{cmd} #{total}"
end
puts
puts '-' * 20
puts
puts "Action top 10:"
action_counter.to_a.sort_by(&:last).reverse[0..10].each do |action, total|
puts " #{action.strip} #{total}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment