Last active
January 4, 2016 12:49
-
-
Save epitron/8624415 to your computer and use it in GitHub Desktop.
Put Pry's history in different files (by date).
This file contains hidden or 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
################################################################### | |
## History | |
PRY_CONFIG_DIR = File.expand_path("~/.pry") | |
Pry.history.loader = proc do |&block| | |
Dir["#{PRY_CONFIG_DIR}/history-*.log"].sort_by { |f| File.mtime f }.last(2).each do |fn| | |
File.foreach(fn) { |line| block.call(line) } | |
end | |
end | |
# history_file = nil | |
Pry.history.saver = proc do |line| | |
if !@history_file | |
filename = "#{PRY_CONFIG_DIR}/history-#{Time.now.strftime('%Y-%m-%d')}.log" | |
@history_file = File.open(filename, 'a', 0600).tap { |f| f.sync = true } | |
end | |
@history_file.puts(line) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment