Skip to content

Instantly share code, notes, and snippets.

@epitron
Last active January 4, 2016 12:49
Show Gist options
  • Save epitron/8624415 to your computer and use it in GitHub Desktop.
Save epitron/8624415 to your computer and use it in GitHub Desktop.
Put Pry's history in different files (by date).
###################################################################
## 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