Created
October 4, 2015 03:27
-
-
Save baweaver/66054f073e8525aef021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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