Skip to content

Instantly share code, notes, and snippets.

@baweaver
Created October 4, 2015 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baweaver/66054f073e8525aef021 to your computer and use it in GitHub Desktop.
Save baweaver/66054f073e8525aef021 to your computer and use it in GitHub Desktop.
# Because screw invalid sequences....
clean = -> s { s.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') }
DateHistory = Struct.new(:date, :command)
dt = DateTime.now
today = DateTime.new(dt.year, dt.month, dt.day, 0, 0, 0)..DateTime.new(dt.year, dt.month, dt.day, 23, 59, 59)
zsh_history.reverse.reduce([]) { |a, l|
line = clean[l]
data = /: (?<date>\d+):\d\;(?<command>.+)$/.match(line) { |m|
DateHistory.new(m[1], m[2]) if m[:date] && today.include?(Time.at(m[:date].to_i).to_date)
}
a << data if data
a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment