Skip to content

Instantly share code, notes, and snippets.

@emanuelhfarias
Created March 9, 2018 02:39
Show Gist options
  • Save emanuelhfarias/c6d140dab3f287460b7c0e8184460663 to your computer and use it in GitHub Desktop.
Save emanuelhfarias/c6d140dab3f287460b7c0e8184460663 to your computer and use it in GitHub Desktop.
zsh history histogram
#!/bin/ruby
require 'pry-byebug'
history_array = []
zsh_history_path = '~/.zhistory'
File.open(zsh_history_path).each do |line|
history_array << line[15..-2]
end
module Enumerable
def to_histogram
inject(Hash.new(0)) { |h, x| h[x] += 1; h}
end
end
histogram = history_array.to_histogram
histogram_sorted = histogram.sort_by {|_key, value| value}
binding.pry
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment