1
0
Fork 0
mirror of https://github.com/vbatts/persistent-shell-history.git synced 2024-12-27 07:06:30 +00:00

efforts to fix the string encoding issues

This commit is contained in:
Vincent Batts 2012-09-20 10:14:07 -04:00
parent 0a6878e75d
commit 2bf3618c09

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# Encoding: UTF-8
require 'digest/md5'
require 'gdbm'
@ -39,9 +40,11 @@ class BashHistory
def _md5(data); Digest::MD5.hexdigest(data); end
def _f(v); " %s %s" % [v[:time].strftime(@options[:time_format]), v[:cmd]]; end
def _e(str, enc = "UTF-8"); str.respond_to?(:force_encoding) ? str.force_encoding(enc) : str; end
def find(pat)
return values.select {|v|
v if v[:cmd] =~ /#{pat}/
v if _e(v[:cmd]) =~ /#{pat}/
}.map {|v|
v[:time].map {|t|
v.merge(:time => t)
@ -52,7 +55,7 @@ class BashHistory
def _parse
open(@options[:file]) do |f|
f.each_line do |line|
if line =~ /^#(.*)$/
if _e(line) =~ /^#(.*)$/
l = f.readline.chomp
key = _md5(l)
if db.has_key?(key)