readline-history-restore 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +0 -0
- data/README +50 -0
- data/Rakefile +104 -0
- data/lib/readline/history/restore.rb +30 -0
- data/lib/readline/history/restore/auto_save.rb +25 -0
- data/lib/readline/history/restore/version.rb +16 -0
- data/test/readline-history-restore_test.rb +11 -0
- data/test/test_helper.rb +2 -0
- metadata +66 -0
data/CHANGELOG
ADDED
File without changes
|
data/README
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= Readline::History::Restore
|
2
|
+
|
3
|
+
== SYNOPSIS
|
4
|
+
|
5
|
+
require 'readline'
|
6
|
+
require 'readline/history/restore'
|
7
|
+
|
8
|
+
# save history automatic when exit ruby program,
|
9
|
+
Readline::History::Restore.new('/home/user/.foobar_history')
|
10
|
+
# with option
|
11
|
+
Readline::History::Restore.new('/home/user/.foobar_history', :history_limit => 100)
|
12
|
+
|
13
|
+
== Install
|
14
|
+
|
15
|
+
gem install readline-history-restore
|
16
|
+
|
17
|
+
== Example
|
18
|
+
|
19
|
+
# example ~/.irbrc
|
20
|
+
# automatic save from scriptname ( don't exec win32 )
|
21
|
+
# if program is '/usr/bin/irb' ,automatic save '~/.ruby_readline_history/%23usr%23bin%23irb'
|
22
|
+
require 'readline/history/restore/auto_save'
|
23
|
+
Readline::History::Restore::AutoSave.scriptname
|
24
|
+
|
25
|
+
== Author
|
26
|
+
|
27
|
+
hotchpotch@no.spam@gmail.com
|
28
|
+
|
29
|
+
== LICENSE
|
30
|
+
|
31
|
+
The MIT License
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
34
|
+
a copy of this software and associated documentation files (the
|
35
|
+
'Software'), to deal in the Software without restriction, including
|
36
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
37
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
38
|
+
permit persons to whom the Software is furnished to do so, subject to
|
39
|
+
the following conditions:
|
40
|
+
|
41
|
+
The above copyright notice and this permission notice shall be
|
42
|
+
included in all copies or substantial portions of the Software.
|
43
|
+
|
44
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
45
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
46
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
47
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
48
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
49
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
50
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'fileutils'
|
10
|
+
include FileUtils
|
11
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
12
|
+
require 'readline/history/restore/version'
|
13
|
+
|
14
|
+
AUTHOR = "secondlife"
|
15
|
+
EMAIL = "hotchpotch@no.spam@gmail.com"
|
16
|
+
DESCRIPTION = "Readline::History::Restore"
|
17
|
+
RUBYFORGE_PROJECT = "rl-history-res"
|
18
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
19
|
+
BIN_FILES = %w( )
|
20
|
+
|
21
|
+
|
22
|
+
NAME = "readline-history-restore"
|
23
|
+
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
24
|
+
VERS = ENV['VERSION'] || (Readline::History::Restore::VERSION::STRING + (REV ? ".#{REV}" : ""))
|
25
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
26
|
+
RDOC_OPTS = ['--quiet', '--title', "Readline::History::Restore documentation",
|
27
|
+
"--opname", "index.html",
|
28
|
+
"--line-numbers",
|
29
|
+
"--main", "README",
|
30
|
+
"--inline-source"]
|
31
|
+
|
32
|
+
desc "Packages up readline-history-restore gem."
|
33
|
+
task :default => [:test]
|
34
|
+
task :package => [:clean]
|
35
|
+
|
36
|
+
Rake::TestTask.new("test") { |t|
|
37
|
+
t.libs << "test"
|
38
|
+
t.pattern = "test/**/*_test.rb"
|
39
|
+
t.verbose = true
|
40
|
+
}
|
41
|
+
|
42
|
+
spec =
|
43
|
+
Gem::Specification.new do |s|
|
44
|
+
s.name = NAME
|
45
|
+
s.version = VERS
|
46
|
+
s.platform = Gem::Platform::RUBY
|
47
|
+
s.has_rdoc = true
|
48
|
+
s.extra_rdoc_files = ["README", "CHANGELOG"]
|
49
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
50
|
+
s.summary = DESCRIPTION
|
51
|
+
s.description = DESCRIPTION
|
52
|
+
s.author = AUTHOR
|
53
|
+
s.email = EMAIL
|
54
|
+
s.homepage = HOMEPATH
|
55
|
+
s.executables = BIN_FILES
|
56
|
+
s.rubyforge_project = RUBYFORGE_PROJECT
|
57
|
+
s.bindir = "bin"
|
58
|
+
s.require_path = "lib"
|
59
|
+
s.autorequire = "readline/history/restore"
|
60
|
+
|
61
|
+
#s.add_dependency('activesupport', '>=1.3.1')
|
62
|
+
#s.required_ruby_version = '>= 1.8.2'
|
63
|
+
|
64
|
+
s.files = %w(README CHANGELOG Rakefile) +
|
65
|
+
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
66
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
67
|
+
Dir.glob("examples/**/*.rb") +
|
68
|
+
Dir.glob("tools/*.rb")
|
69
|
+
|
70
|
+
# s.extensions = FileList["ext/**/extconf.rb"].to_a
|
71
|
+
end
|
72
|
+
|
73
|
+
Rake::GemPackageTask.new(spec) do |p|
|
74
|
+
p.need_tar = true
|
75
|
+
p.gem_spec = spec
|
76
|
+
end
|
77
|
+
|
78
|
+
task :install do
|
79
|
+
name = "#{NAME}-#{VERS}.gem"
|
80
|
+
sh %{rake package}
|
81
|
+
sh %{sudo gem install pkg/#{name}}
|
82
|
+
end
|
83
|
+
|
84
|
+
task :uninstall => [:clean] do
|
85
|
+
sh %{sudo gem uninstall #{NAME}}
|
86
|
+
end
|
87
|
+
|
88
|
+
Rake::RDocTask.new { |rdoc|
|
89
|
+
rdoc.rdoc_dir = 'html'
|
90
|
+
rdoc.options += RDOC_OPTS
|
91
|
+
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
92
|
+
if ENV['DOC_FILES']
|
93
|
+
rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
94
|
+
else
|
95
|
+
rdoc.rdoc_files.include('README', 'CHANGELOG')
|
96
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
97
|
+
end
|
98
|
+
}
|
99
|
+
|
100
|
+
desc "Publish to RubyForge"
|
101
|
+
task :rubyforge => [:rdoc, :package] do
|
102
|
+
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'secondlife').upload
|
103
|
+
end
|
104
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'readline'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Readline
|
6
|
+
module History
|
7
|
+
class Restore
|
8
|
+
def initialize(filename, options = {})
|
9
|
+
raise 'must filenae' unless filename && !filename.empty?
|
10
|
+
@filepath = Pathname.new filename
|
11
|
+
load_history @filepath
|
12
|
+
@history_limit = options[:history_limit] || 10000
|
13
|
+
@finalizer = at_exit { save_history @filepath }
|
14
|
+
self
|
15
|
+
end
|
16
|
+
attr_accessor :history_limit, :finalizer
|
17
|
+
|
18
|
+
def load_history(filepath)
|
19
|
+
filepath.readlines.each { |line| Readline::HISTORY << line.chomp } if filepath.file?
|
20
|
+
end
|
21
|
+
|
22
|
+
def save_history(filepath)
|
23
|
+
filepath.parent.mkpath unless filepath.parent.directory?
|
24
|
+
filepath.open('w') do |f|
|
25
|
+
Readline::HISTORY.to_a.last(@history_limit).each {|l| f.puts l unless l.empty? }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'readline'
|
2
|
+
require 'readline/history/restore'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
module Readline
|
7
|
+
module History
|
8
|
+
class Restore
|
9
|
+
module AutoSave
|
10
|
+
AUTOSAVE_HOME = ENV['RUBY_READLINE_AUTOSAVE'] || ENV['HOME'] + '/.ruby_readline_history/'
|
11
|
+
|
12
|
+
def scriptname(options = {}) # :don't use win32
|
13
|
+
unless fn = ENV['_']
|
14
|
+
raise "don't found scriptfile name"
|
15
|
+
end
|
16
|
+
home = Pathname.new(options[:history_home] || AUTOSAVE_HOME)
|
17
|
+
home.mkpath unless home.directory?
|
18
|
+
history = home.join(Pathname.new(fn).realpath.to_s.gsub('/', '%23'))
|
19
|
+
Readline::History::Restore.new(history.to_s)
|
20
|
+
end
|
21
|
+
module_function :scriptname
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: readline-history-restore
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2006-11-10 00:00:00 +09:00
|
8
|
+
summary: Readline::History::Restore
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: hotchpotch@no.spam@gmail.com
|
12
|
+
homepage: http://rl-history-res.rubyforge.org
|
13
|
+
rubyforge_project: rl-history-res
|
14
|
+
description: Readline::History::Restore
|
15
|
+
autorequire: readline/history/restore
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- secondlife
|
30
|
+
files:
|
31
|
+
- README
|
32
|
+
- CHANGELOG
|
33
|
+
- Rakefile
|
34
|
+
- test/readline-history-restore_test.rb
|
35
|
+
- test/test_helper.rb
|
36
|
+
- lib/readline
|
37
|
+
- lib/readline/history
|
38
|
+
- lib/readline/history/restore
|
39
|
+
- lib/readline/history/restore.rb
|
40
|
+
- lib/readline/history/restore/auto_save.rb
|
41
|
+
- lib/readline/history/restore/version.rb
|
42
|
+
test_files: []
|
43
|
+
|
44
|
+
rdoc_options:
|
45
|
+
- --quiet
|
46
|
+
- --title
|
47
|
+
- Readline::History::Restore documentation
|
48
|
+
- --opname
|
49
|
+
- index.html
|
50
|
+
- --line-numbers
|
51
|
+
- --main
|
52
|
+
- README
|
53
|
+
- --inline-source
|
54
|
+
- --exclude
|
55
|
+
- ^(examples|extras)/
|
56
|
+
extra_rdoc_files:
|
57
|
+
- README
|
58
|
+
- CHANGELOG
|
59
|
+
executables: []
|
60
|
+
|
61
|
+
extensions: []
|
62
|
+
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
dependencies: []
|
66
|
+
|