yap-shell 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.travis.lock +104 -0
  3. data/bin/yap +6 -0
  4. data/bin/yap-dev +37 -0
  5. data/lib/yap.rb +29 -39
  6. data/lib/yap/addon.rb +24 -0
  7. data/lib/yap/addon/base.rb +52 -0
  8. data/lib/yap/addon/export_as.rb +12 -0
  9. data/lib/yap/addon/loader.rb +84 -0
  10. data/lib/yap/addon/path.rb +56 -0
  11. data/lib/yap/addon/rc_file.rb +21 -0
  12. data/lib/yap/addon/reference.rb +22 -0
  13. data/lib/yap/cli.rb +4 -0
  14. data/lib/yap/cli/commands.rb +6 -0
  15. data/lib/yap/cli/commands/addon.rb +14 -0
  16. data/lib/yap/cli/commands/addon/disable.rb +35 -0
  17. data/lib/yap/cli/commands/addon/enable.rb +35 -0
  18. data/lib/yap/cli/commands/addon/list.rb +37 -0
  19. data/lib/yap/cli/commands/addon/search.rb +99 -0
  20. data/lib/yap/cli/commands/generate.rb +13 -0
  21. data/lib/yap/cli/commands/generate/addon.rb +258 -0
  22. data/lib/yap/cli/commands/generate/addonrb.template +22 -0
  23. data/lib/yap/cli/commands/generate/gemspec.template +25 -0
  24. data/lib/yap/cli/commands/generate/license.template +21 -0
  25. data/lib/yap/cli/commands/generate/rakefile.template +6 -0
  26. data/lib/yap/cli/commands/generate/readme.template +40 -0
  27. data/lib/yap/cli/options.rb +162 -0
  28. data/lib/yap/cli/options/addon.rb +64 -0
  29. data/lib/yap/cli/options/addon/disable.rb +62 -0
  30. data/lib/yap/cli/options/addon/enable.rb +63 -0
  31. data/lib/yap/cli/options/addon/list.rb +65 -0
  32. data/lib/yap/cli/options/addon/search.rb +76 -0
  33. data/lib/yap/cli/options/generate.rb +59 -0
  34. data/lib/yap/cli/options/generate/addon.rb +63 -0
  35. data/lib/yap/configuration.rb +10 -3
  36. data/lib/yap/gem_helper.rb +195 -0
  37. data/lib/yap/gem_tasks.rb +6 -0
  38. data/lib/yap/shell.rb +1 -1
  39. data/lib/yap/shell/repl.rb +1 -1
  40. data/lib/yap/shell/version.rb +1 -1
  41. data/lib/yap/world.rb +45 -7
  42. data/rcfiles/yaprc +90 -10
  43. data/spec/features/addons/generating_an_addon_spec.rb +55 -0
  44. data/spec/features/addons/using_an_addon_spec.rb +182 -0
  45. data/spec/features/aliases_spec.rb +6 -6
  46. data/spec/features/grouping_spec.rb +18 -18
  47. data/spec/features/line_editing_spec.rb +9 -1
  48. data/spec/features/redirection_spec.rb +12 -3
  49. data/spec/spec_helper.rb +21 -11
  50. data/spec/support/matchers/have_printed.rb +38 -0
  51. data/spec/support/yap_spec_dsl.rb +24 -6
  52. data/yap-shell.gemspec +6 -11
  53. metadata +51 -45
  54. data/addons/history/README.md +0 -16
  55. data/addons/history/history.rb +0 -58
  56. data/addons/history_search/history_search.rb +0 -197
  57. data/addons/keyboard_macros/keyboard_macros.rb +0 -425
  58. data/addons/keyboard_macros/lib/keyboard_macros/cycle.rb +0 -38
  59. data/addons/prompt/Gemfile +0 -1
  60. data/addons/prompt/right_prompt.rb +0 -17
  61. data/addons/prompt_updates/prompt_updates.rb +0 -28
  62. data/addons/tab_completion/Gemfile +0 -0
  63. data/addons/tab_completion/lib/tab_completion/basic_completion.rb +0 -151
  64. data/addons/tab_completion/lib/tab_completion/completer.rb +0 -62
  65. data/addons/tab_completion/lib/tab_completion/custom_completion.rb +0 -33
  66. data/addons/tab_completion/lib/tab_completion/dsl_methods.rb +0 -7
  67. data/addons/tab_completion/tab_completion.rb +0 -174
  68. data/lib/tasks/addons.rake +0 -97
  69. data/lib/yap/world/addons.rb +0 -181
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7186e70881e605ba5563cd30e9674030c55f4332
4
- data.tar.gz: abbfa86bde0fabf472adca6a87843588e8760671
3
+ metadata.gz: b745bf1643f4cc00a8863cd3bd0ea4a418f1404a
4
+ data.tar.gz: 0db3fb4d29ec34e83176c5acb7c39f27106ec027
5
5
  SHA512:
6
- metadata.gz: 4498e667793d6009c6a988fd85b3977b7a01d79dee15565e71b9c6b10cc86a844263f9215205bf382e9ad152fde34589890d022a7bdb92d536204e3595df967f
7
- data.tar.gz: fb6bff600285457f6aeea74c1fb5bf8d843dbba8b4a3b17c791b69ebd5dd93a5c1e2e0f7b7a660ed64afe468e49a3e2a73801a643d17fa811bfa6055ced9710f
6
+ metadata.gz: ac7bb1a89d06d54b01084d9ac30d4603e2d383f8f294b24470749aa9946cd8cb9bb0693a24ff05828ae14a1392266d782fa4a173ea09773ab36f3a1cfbfca754
7
+ data.tar.gz: 12347f2b492455fc8b9068c229cc8efae97bdac7bafaecc5faf343ab7d4cd02040a796c3d291c92879c86a7dfde549bbed0e3603720b01ca68e52dc1fef4d3ce
@@ -0,0 +1,104 @@
1
+ GIT
2
+ remote: https://github.com/zdennis/rawline.git
3
+ revision: 242e1946383811297b6180f327233f6d2108ae15
4
+ specs:
5
+ yap-rawline (0.5.1)
6
+ highline (~> 1.7, >= 1.7.2)
7
+ term-ansicolor (~> 1.3.0)
8
+ terminal-layout (~> 0.4.0)
9
+ treefell (~> 0.2.3)
10
+
11
+ GIT
12
+ remote: https://github.com/zdennis/terminal-layout.git
13
+ revision: 976050c3a56a2a073934d4cfec2d0aeed163e857
14
+ specs:
15
+ terminal-layout (0.4.0)
16
+ highline (~> 1.7, >= 1.7.8)
17
+ ruby-terminfo (~> 0.1.1)
18
+ ruby-termios (~> 0.9.6)
19
+ treefell (~> 0.2.3)
20
+
21
+ GIT
22
+ remote: https://github.com/zdennis/treefell.git
23
+ revision: 09e527ba07b413947d93c52a13cd5dd470d7b1fc
24
+ specs:
25
+ treefell (0.2.3)
26
+ term-ansicolor (~> 1.3)
27
+
28
+ GIT
29
+ remote: https://github.com/zdennis/yap-shell-parser.git
30
+ revision: 6b8390ecdd47b58f2550d4844e7a285cc1bbc4aa
31
+ specs:
32
+ yap-shell-parser (0.7.0)
33
+ term-ansicolor (~> 1.3.0)
34
+ treefell (~> 0.2.3)
35
+
36
+ PATH
37
+ remote: .
38
+ specs:
39
+ yap-shell (0.6.0)
40
+ chronic (~> 0.10.2)
41
+ pry-byebug (~> 3.3)
42
+ ruby-terminfo (~> 0.1.1)
43
+ ruby-termios (~> 0.9.6)
44
+ term-ansicolor (~> 1.3)
45
+ treefell (~> 0.2.3)
46
+ yap-rawline (~> 0.5.1)
47
+ yap-shell-parser (~> 0.7.0)
48
+
49
+ GEM
50
+ remote: https://rubygems.org/
51
+ specs:
52
+ byebug (9.0.5)
53
+ childprocess (0.5.9)
54
+ ffi (~> 1.0, >= 1.0.11)
55
+ chronic (0.10.2)
56
+ coderay (1.1.1)
57
+ diff-lcs (1.2.5)
58
+ ffi (1.9.10)
59
+ highline (1.7.8)
60
+ method_source (0.8.2)
61
+ pry (0.10.3)
62
+ coderay (~> 1.1.0)
63
+ method_source (~> 0.8.1)
64
+ slop (~> 3.4)
65
+ pry-byebug (3.4.0)
66
+ byebug (~> 9.0)
67
+ pry (~> 0.10)
68
+ rake (11.2.2)
69
+ rspec (3.4.0)
70
+ rspec-core (~> 3.4.0)
71
+ rspec-expectations (~> 3.4.0)
72
+ rspec-mocks (~> 3.4.0)
73
+ rspec-core (3.4.4)
74
+ rspec-support (~> 3.4.0)
75
+ rspec-expectations (3.4.0)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.4.0)
78
+ rspec-mocks (3.4.1)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.4.0)
81
+ rspec-support (3.4.1)
82
+ ruby-terminfo (0.1.1)
83
+ ruby-termios (0.9.6)
84
+ slop (3.6.0)
85
+ term-ansicolor (1.3.2)
86
+ tins (~> 1.0)
87
+ tins (1.10.2)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ bundler (~> 1.6)
94
+ childprocess (~> 0.5.9)
95
+ rake (~> 11)
96
+ rspec (~> 3.0)
97
+ terminal-layout!
98
+ treefell!
99
+ yap-rawline!
100
+ yap-shell!
101
+ yap-shell-parser!
102
+
103
+ BUNDLED WITH
104
+ 1.12.5
data/bin/yap CHANGED
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ ENV['PWD'] = Dir.pwd
4
+
3
5
  # Start YAP with a pristine environment
4
6
  env2keep = {
5
7
  # DISPLAY needs to be inherited in order to launch GUI apps
6
8
  'DISPLAY' => ENV['DISPLAY'],
7
9
  'HOME' => ENV['HOME'],
8
10
  'PATH' => ENV['PATH'],
11
+ 'PWD' => ENV['PWD'],
9
12
 
10
13
  # For Yap's sanity
11
14
  'RUBYOPT' => '-rubygems -EUTF-8',
@@ -13,6 +16,9 @@ env2keep = {
13
16
  # Inherit the user's preferred shell
14
17
  'SHELL' => ENV['SHELL'],
15
18
 
19
+ # Set the logged in user
20
+ 'USER' => ENV['USER'],
21
+
16
22
  # Necessary for ssh-agent
17
23
  'SSH_AUTH_SOCK' => ENV['SSH_AUTH_SOCK'],
18
24
 
data/bin/yap-dev CHANGED
@@ -4,5 +4,42 @@ require 'bundler'
4
4
  Bundler.setup
5
5
  require 'pry'
6
6
 
7
+ module SilenceWarnings
8
+ # Runs a block of code without warnings.
9
+ def self.silence_warnings(&block)
10
+ warn_level = $VERBOSE
11
+ $VERBOSE = nil
12
+ result = block.call
13
+ $VERBOSE = warn_level
14
+ result
15
+ end
16
+ end
17
+
18
+ ### START debundle.rb ###
19
+
20
+ # MIT License
21
+ # Copyright (c) Conrad Irwin <conrad.irwin@gmail.com>
22
+ # Copyright (c) Jan Lelis <mail@janlelis.de>
23
+
24
+ module Debundle
25
+ VERSION = '1.0.0'
26
+
27
+ def self.debundle!
28
+ if Gem.post_reset_hooks.reject!{ |hook| hook.source_location.first =~ %r{/bundler/} }
29
+ Gem.clear_paths
30
+ SilenceWarnings.silence_warnings do
31
+ load 'rubygems/core_ext/kernel_require.rb'
32
+ load 'rubygems/core_ext/kernel_gem.rb'
33
+ end
34
+ end
35
+ rescue => e
36
+ warn "DEBUNDLE.RB FAILED: #{e.class}\n#{e.message}"
37
+ end
38
+ end
39
+
40
+ Debundle.debundle!
41
+
42
+ ### END debundle.rb ###
43
+
7
44
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
8
45
  load File.dirname(__FILE__) + '/yap'
data/lib/yap.rb CHANGED
@@ -6,57 +6,47 @@ require "treefell"
6
6
  require 'optparse'
7
7
 
8
8
  module Yap
9
+ require 'yap/cli/options'
9
10
  require 'yap/configuration'
10
11
  require 'yap/shell'
11
12
  require 'yap/world'
12
13
 
13
- def self.parse_cli_args_for_configuration(args, configuration)
14
- OptionParser.new do |opts|
15
- opts.on('-h', '--help', 'Prints this help') do
16
- puts opts
17
- exit
18
- end
19
-
20
- opts.on('--skip-first-time', 'Disables creating ~/.yap directory on shell startup') do
21
- configuration.skip_first_time = true
22
- end
23
-
24
- opts.on('--no-addons', 'Disables auto-loading addons on shell startup') do
25
- configuration.use_addons = false
26
- end
27
-
28
- opts.on('--no-history', 'Disables auto-loading or saving history') do
29
- configuration.use_history = false
30
- end
31
-
32
- opts.on('--no-rcfiles', 'Disables auto-loading rcfiles on shell startup') do
33
- configuration.use_rcfiles = false
34
- end
35
- end.parse!(args)
14
+ def self.root
15
+ Pathname.new File.join(File.dirname(__FILE__), '..')
36
16
  end
37
17
 
38
18
  def self.run_shell(argv)
39
19
  Treefell['shell'].puts "#{self}.#{__callee__} booting shell"
40
20
 
41
- parse_cli_args_for_configuration(argv, configuration)
21
+ yap_options = Yap::Cli::Options.new
22
+ yap_options.parse(argv)
42
23
 
43
- addons_loaded = []
44
- if configuration.use_addons?
45
- Treefell['shell'].puts "#{self}.#{__callee__} loading addons"
46
- addons_loaded.concat \
47
- World::Addons.load_directories(configuration.addon_paths)
48
- else
49
- Treefell['shell'].puts "#{self}.#{__callee__} skipping addons"
50
- end
24
+ if configuration.run_shell?
25
+ configuration.yap_binpath = File.expand_path($0)
26
+
27
+ addons_loaded = []
28
+ if configuration.use_addons?
29
+ Treefell['shell'].puts "#{self}.#{__callee__} loading addons"
30
+ addons = Yap::Addon.load_for_configuration(configuration)
31
+ addons_loaded.concat addons
32
+ else
33
+ Treefell['shell'].puts "#{self}.#{__callee__} skipping addons"
34
+ end
35
+
36
+ if configuration.use_rcfiles?
37
+ Treefell['shell'].puts "#{self}.#{__callee__} loading rcfiles"
38
+ addons_loaded.concat \
39
+ Yap::Addon.load_rcfiles(configuration.rcfiles)
40
+ else
41
+ Treefell['shell'].puts "#{self}.#{__callee__} skipping rcfiles"
42
+ end
51
43
 
52
- if configuration.use_rcfiles?
53
- Treefell['shell'].puts "#{self}.#{__callee__} loading rcfiles"
54
- addons_loaded.concat \
55
- World::Addons.load_rcfiles(configuration.rcfiles)
44
+ Shell::Impl.new(addons: addons_loaded).repl
45
+ elsif yap_options.commands.any?
46
+ yap_options.commands.last.process
56
47
  else
57
- Treefell['shell'].puts "#{self}.#{__callee__} skipping rcfiles"
48
+ STDERR.puts "Honestly, I don't know what you're tring to do."
49
+ exit 1
58
50
  end
59
-
60
- Shell::Impl.new(addons: addons_loaded).repl
61
51
  end
62
52
  end
data/lib/yap/addon.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'yap/addon/base'
2
+ require 'yap/addon/export_as'
3
+ require 'yap/addon/loader'
4
+ require 'yap/addon/path'
5
+ require 'yap/addon/rc_file'
6
+ require 'yap/addon/reference'
7
+
8
+ module Yap
9
+ module Addon
10
+ def self.load_rcfiles(files)
11
+ Yap::Addon::Loader.load_rcfiles(files)
12
+ end
13
+
14
+ def self.load_for_configuration(configuration)
15
+ addon_references = Yap::Addon::Path.find_for_configuration(configuration)
16
+ Yap::Addon::Loader.new(addon_references).load_all
17
+ end
18
+
19
+ def self.export_as_for_gemspec(gemspec)
20
+ addonrb_path = File.join('lib', gemspec.name + '.rb')
21
+ ExportAs.find_in_file(addonrb_path)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,52 @@
1
+ module Yap
2
+ module Addon
3
+ class Base
4
+ def self.load_addon
5
+ @instance ||= new
6
+ end
7
+
8
+ def self.addon_name
9
+ @addon_name ||= begin
10
+ addon_name = self.name.split(/::/)
11
+ .last.scan(/[A-Z][^A-Z]+/)
12
+ .map(&:downcase).reject{ |f| f == "addon" }
13
+ .join("_")
14
+ .to_sym
15
+ addon_name.length == 0 ? self.name : addon_name
16
+ end
17
+ end
18
+
19
+ def self.export_as(name=nil)
20
+ if name
21
+ @export_as = name.to_sym
22
+ end
23
+ @export_as
24
+ end
25
+
26
+ def self.logger
27
+ calling_method = caller[1][/`.*'/][1..-2]
28
+ Treefell["addon:#{export_as}"]["#{name}##{calling_method}"]
29
+ end
30
+
31
+ def addon_name
32
+ @addon_name ||= self.class.addon_name
33
+ end
34
+
35
+ def logger
36
+ self.class.logger
37
+ end
38
+
39
+ def export_as
40
+ self.class.export_as
41
+ end
42
+
43
+ def initialize(enabled: true)
44
+ @yap_enabled = enabled
45
+ end
46
+
47
+ def yap_enabled?
48
+ @yap_enabled
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ module Yap
2
+ module Addon
3
+ module ExportAs
4
+ def self.find_in_file(path)
5
+ export_as = File.read(path).
6
+ scan(/export_as\(?\s*:?(['"]?)(.*)\1/).
7
+ flatten.
8
+ last
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,84 @@
1
+ module Yap
2
+ module Addon
3
+ class Loader
4
+ def initialize(addon_references)
5
+ @addon_references = addon_references
6
+ end
7
+
8
+ def load_all
9
+ @addon_references.map do |reference|
10
+ load_reference(reference)
11
+ end.compact
12
+ end
13
+
14
+ private
15
+
16
+ def bring_addon_into_existence(reference)
17
+ require reference.require_as
18
+ classified_name = reference.require_as.split('-').map(&:capitalize).join
19
+ unless Object.const_defined?(classified_name)
20
+ fail LoadError, "Expected #{name}.rb to load #{classified_name}, but it didn't"
21
+ end
22
+
23
+ addon = Object.const_get(classified_name)
24
+ addon_class = if addon.is_a?(Addon)
25
+ addon
26
+ elsif addon.const_defined?(:Addon)
27
+ addon.const_get(:Addon)
28
+ else
29
+ fail LoadError, "Expected gem #{name} to define a constant, but nothing was found"
30
+ end
31
+ addon_class.new enabled: reference.enabled?
32
+ end
33
+
34
+ def load_reference(reference)
35
+ begin
36
+ if Gem.path.any? { |path| reference.path.include?(path) }
37
+ load_gem reference
38
+ else
39
+ load_non_gem reference
40
+ end
41
+ rescue Exception => ex
42
+ puts Term::ANSIColor.red("Rut roh! The #{reference.name} addon failed to load.")
43
+ puts
44
+ puts ex.message
45
+ puts
46
+ puts "To uninstall this addon:"
47
+ puts
48
+ puts " gem uninstall #{reference.require_as}"
49
+ puts
50
+ puts "Note: this did not stop yap from loading, but functionality from the addon will be missing."
51
+ end
52
+ end
53
+
54
+ def load_gem(reference)
55
+ gem reference.require_as
56
+ bring_addon_into_existence reference
57
+ end
58
+
59
+ def load_non_gem(reference)
60
+ lib_path = File.expand_path File.join(reference.path, 'lib')
61
+ Treefell['addon'].puts "prepending addon path to $LOAD_PATH: #{lib_path}"
62
+ $LOAD_PATH.unshift lib_path
63
+
64
+ bring_addon_into_existence reference
65
+ ensure
66
+ Treefell['addon'].puts "Removing addon #{lib_path} path from $LOAD_PATH"
67
+ $LOAD_PATH.delete(lib_path)
68
+ end
69
+
70
+ def self.load_rcfiles(files)
71
+ Treefell['addon'].puts %|searching for rcfiles:\n * #{files.join("\n * ")}|
72
+ files.map do |file|
73
+ if File.exists?(file)
74
+ Treefell['addon'].puts "rcfile #{file} found, loading."
75
+ RcFile.new file
76
+ else
77
+ Treefell['addon'].puts "rcfile #{file} not found, skipping."
78
+ end
79
+ end.flatten.compact
80
+ end
81
+
82
+ end
83
+ end
84
+ end