yap-shell-addon-history 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f225f7f8a96a37e251e59d3a04ef272580eef13d
4
+ data.tar.gz: f3ceb4f3e76d016278f6b35d413c353dc836023a
5
+ SHA512:
6
+ metadata.gz: 36ecd7187c1509a8e2fc78f359649392dcb839904d211e04099d546edd47eaa0f6ca1b0df9812f9f53322bbc58aebee7823468f2898386fca5355f30d6be1259
7
+ data.tar.gz: b4dcca6eaffde1a322a2fae81826c793aca79b0ea03a5386a260672f85c72b0f526cdde84825a96f093e992285d4c44924ad0c28dff8b1e2ce3e9a46e8874dc0
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ wiki/
@@ -0,0 +1 @@
1
+ 2.3.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yap-shell-addon-history.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Zach Dennis
4
+
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # History for yap-shell
2
+
3
+ The History addon is provides primitive history capabilities:
4
+
5
+ * Loads history from ~/.yap/history when yap is loaded
6
+ * Saves history to ~/.yap/history when yap exits
7
+ * Saving is an append-only operation
8
+ * ~/.yap/history is in YAML format
9
+
10
+ ## Shell Functions
11
+
12
+ The history addon provides the `history` shell function that prints the contents of the history.
13
+
14
+ ## Limitations
15
+
16
+ The history addon currently does not support any kind of advanced history operations.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'yap-shell-addon-history'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install yap-shell-addon-history
33
+
34
+ ## Usage
35
+
36
+ TODO: Write usage instructions here
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yap-shell-addon-history.
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "yap/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,89 @@
1
+ require 'yap/addon'
2
+ require 'yap-shell-addon-history/version'
3
+
4
+ module YapShellAddonHistory
5
+ class Addon < ::Yap::Addon::Base
6
+ self.export_as :history
7
+
8
+ attr_reader :file
9
+ attr_reader :position
10
+
11
+ def initialize_world(world)
12
+ return unless world.configuration.use_history?
13
+ @world = world
14
+
15
+ @file = world.configuration.path_for('history')
16
+ @position = 0
17
+
18
+ load_history
19
+
20
+ world.func(:history) do |args:, stdin:, stdout:, stderr:|
21
+ history_length = @world.editor.history.length
22
+ first_arg = args.first.to_i
23
+ size = first_arg > 0 ? first_arg + 1 : history_length
24
+
25
+ # start from -2 since we don't want to include the current history
26
+ # command being run.
27
+ stdout.puts @world.editor.history[history_length-size..-2]
28
+ end
29
+ end
30
+
31
+ def back
32
+ logger.puts "entered"
33
+ current_position = @world.editor.line.text_up_to_position
34
+ found_text = @world.history.find_match_backward(@world.editor.line.text_up_to_position)
35
+ if found_text
36
+ logger.puts "match found: #{found_text.inspect}"
37
+ @world.editor.overwrite_line found_text, position: :preserve
38
+ else
39
+ logger.puts "no match found"
40
+ end
41
+ end
42
+
43
+ def forward
44
+ logger.puts "entered"
45
+ current_position = @world.editor.line.text_up_to_position
46
+ found_text = @world.history.find_match_forward(@world.editor.line.text_up_to_position)
47
+ if found_text
48
+ logger.puts "match found: #{found_text.inspect}"
49
+ @world.editor.overwrite_line found_text, position: :preserve
50
+ else
51
+ logger.puts "no match found"
52
+ end
53
+ end
54
+
55
+ def save
56
+ logger.puts "saving history file=#{file.inspect}"
57
+ File.open(file, "a") do |file|
58
+ # Don't write the YAML header because we're going to append to the
59
+ # history file, not overwrite. YAML works fine without it.
60
+ unwritten_history = @world.editor.history.to_a[@position..-1]
61
+ if unwritten_history.any?
62
+ contents = unwritten_history
63
+ .each_with_object([]) { |line, arr| arr << line unless line == arr.last }
64
+ .map { |str| str.respond_to?(:without_ansi) ? str.without_ansi : str }
65
+ .to_yaml
66
+ .gsub(/^---.*?^/m, '')
67
+ file.write contents
68
+ end
69
+ end
70
+ end
71
+
72
+ private
73
+
74
+ def load_history
75
+ logger.puts "loading history file=#{file.inspect}"
76
+ at_exit { save }
77
+
78
+ if File.exists?(file) && File.readable?(file)
79
+ history = YAML.load_file(file) || []
80
+
81
+ # History starts at the end of the history loaded from file.
82
+ @position = history.length
83
+
84
+ # Rely on the builtin history for now.
85
+ @world.editor.history.replace(history)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ module YapShellAddonHistory
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/lib/yap-shell-addon-history/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'yap-shell-addon-history'
5
+ spec.version = YapShellAddonHistory::VERSION
6
+ spec.authors = ['Your name']
7
+ spec.email = 'you@example.com'
8
+ spec.date = Date.today.to_s
9
+
10
+ spec.summary = 'history summary goes here.'
11
+ spec.description = 'history description goes here.'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(/^(test|spec|features)\//) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "yap-shell", "~> 0.6"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 11.2"
24
+ spec.add_development_dependency "rspec", "~> 3.4"
25
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yap-shell-addon-history
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Your name
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yap-shell
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ description: history description goes here.
70
+ email: you@example.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".ruby-version"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/yap-shell-addon-history.rb
82
+ - lib/yap-shell-addon-history/version.rb
83
+ - yap-shell-addon-history.gemspec
84
+ homepage: ''
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.5.1
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: history summary goes here.
108
+ test_files: []
109
+ has_rdoc: