Permalink
Browse files

Added option :history_uniq to control uniqueness of history entries (…

…true, false, reverse).
  • Loading branch information...
1 parent f8b0441 commit ebc28c13a3cf2b09e779ab1936a973e708e867fd @blackwinter blackwinter committed Sep 1, 2009
Showing with 14 additions and 2 deletions.
  1. +14 −2 lib/wirble.rb
View
16 lib/wirble.rb
@@ -70,6 +70,7 @@ class History
:history_path => ENV['IRB_HISTORY_FILE'] || "~/.irb_history",
:history_size => (ENV['IRB_HISTORY_SIZE'] || 1000).to_i,
:history_perms => File::WRONLY | File::CREAT | File::TRUNC,
+ :history_uniq => true,
}
private
@@ -83,10 +84,21 @@ def cfg(key)
end
def save_history
- path, max_size, perms = %w{path size perms}.map { |v| cfg(v) }
+ path, max_size, perms, uniq = %w{path size perms uniq}.map { |v| cfg(v) }
# read lines from history, and truncate the list (if necessary)
- lines = Readline::HISTORY.to_a.uniq
+ lines = Readline::HISTORY.to_a
+
+ if uniq
+ if uniq.to_s == 'reverse'
+ lines.reverse!
+ lines.uniq!
+ lines.reverse!
+ else
+ lines.uniq!
+ end
+ end
+
lines = lines[-max_size, -1] if lines.size > max_size
# write the history file

0 comments on commit ebc28c1

Please sign in to comment.