From 106aead4620dc5d56c74c513f49dfb0600a44085 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Wed, 11 Dec 2013 15:43:57 -0500 Subject: [PATCH] fixing encoding issues for newer ruby --- lib/persistent-shell-history/binary-history-store.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/persistent-shell-history/binary-history-store.rb b/lib/persistent-shell-history/binary-history-store.rb index 202c041..5e6cf6a 100644 --- a/lib/persistent-shell-history/binary-history-store.rb +++ b/lib/persistent-shell-history/binary-history-store.rb @@ -1,4 +1,3 @@ - require 'digest/md5' require 'gdbm' require 'yaml' @@ -7,6 +6,11 @@ require 'persistent-shell-history/abstract-history-store' require 'persistent-shell-history/history' require 'persistent-shell-history/command' +if RUBY_VERSION >= "1.9" # assuming you're running Ruby ~1.9 + Encoding.default_external = Encoding::UTF_8 + Encoding.default_internal = Encoding::UTF_8 +end + module Persistent module Shell class BinaryHistoryStore < AbstractHistoryStore @@ -51,7 +55,7 @@ module Persistent # display a formatted time commend def fmt(cmd); " %s %s" % [Time.at(cmd[:time]).strftime(@options[:time_format]), cmd[:cmd]]; end - + def find(pat) return values.select {|v| v if v[:cmd] =~ /#{pat}/ @@ -61,7 +65,7 @@ module Persistent } }.flatten end - + def load(filename = @options[:file]) open(filename) do |f| f.each_line do |line|