yap-shell 0.0.2

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/rcfiles/.yaprc ADDED
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'chronic'
4
+ require 'term/ansicolor'
5
+
6
+ #
7
+ # Configuring your prompt. This can be set to a static value or to a
8
+ # Proc like object that responds to #call. If it responds to call it will
9
+ # be used every time the prompt is to be re-drawn
10
+ #
11
+
12
+ self.prompt = -> do
13
+ pwd = Dir.pwd.sub Regexp.new(ENV['HOME']), '~'
14
+
15
+ git_current_branch = `git cbranch 2>/dev/null`.chomp
16
+ if git_current_branch.length > 0
17
+ git_current_branch += " "
18
+ git_dirty_not_cached = `git diff --shortstat`.length > 0
19
+ git_dirty_cached = `git diff --shortstat --cached`.length > 0
20
+
21
+ if git_dirty_not_cached || git_dirty_cached
22
+ git_branch = intense_cyan(git_current_branch)
23
+ else
24
+ git_branch = cyan(git_current_branch)
25
+ end
26
+ else
27
+ git_branch = ""
28
+ end
29
+
30
+ arrow = '➜'
31
+
32
+ # ~/source/playground/yap master ➜
33
+ "#{dark(green('£'))} #{yellow(pwd)} #{git_branch}#{red(arrow)} "
34
+ end
35
+
36
+ func :howmuch do |args:, stdin:, stdout:, stderr:|
37
+ case args.first
38
+ when "time"
39
+ if history_item=CommandHistory.last_run_command
40
+ stdout.puts history_item.total_time_s
41
+ else
42
+ stdout.puts "Can't report on something you haven't done."
43
+ end
44
+ else
45
+ stdout.puts "How much what?"
46
+ end
47
+ end
48
+
49
+ func :upcase do |args:, stdin:, stdout:, stderr:|
50
+ str = stdin.read
51
+ stdout.puts str.upcase
52
+ end
53
+
54
+ class CommandHistoryImplementation
55
+ def initialize
56
+ @history = []
57
+ end
58
+
59
+ def start_group(time)
60
+ @group = Group.new(started_at:time)
61
+ @history.push @group
62
+ end
63
+
64
+ def stop_group(time)
65
+ @group.stopped_at(time)
66
+ end
67
+
68
+ def push(item)
69
+ @group.add_item item
70
+ end
71
+
72
+ def last_group
73
+ @history.last
74
+ end
75
+
76
+ def last_command
77
+ return @history.last.last_item if @history.last
78
+ nil
79
+ end
80
+
81
+ def last_run_command
82
+ @history.reverse.each do |group|
83
+ last_run = group.items.reverse.detect{ |item| item.finished? }
84
+ break last_run if last_run
85
+ end
86
+ end
87
+
88
+ class Group
89
+ def initialize(started_at:Time.now)
90
+ @started_at = started_at
91
+ @items = []
92
+ end
93
+
94
+ def add_item(item)
95
+ @items.push item
96
+ end
97
+
98
+ def items
99
+ @items
100
+ end
101
+
102
+ def last_item
103
+ @items.last
104
+ end
105
+
106
+ def stopped_at(time)
107
+ @stopped_at ||= time
108
+ end
109
+
110
+ def duration
111
+ return nil unless @stopped_at
112
+ @stopped_at - @started_at
113
+ end
114
+ end
115
+
116
+ class Item
117
+ def initialize(command_str:command_str, started_at:Time.now)
118
+ @command_str = command_str
119
+ @started_at = started_at
120
+ @ended_at = nil
121
+ end
122
+
123
+ def finished!
124
+ @ended_at = Time.now
125
+ end
126
+
127
+ def finished?
128
+ !!@ended_at
129
+ end
130
+
131
+ def total_time_s
132
+ humanize(@ended_at - @started_at) if @ended_at && @started_at
133
+ end
134
+
135
+ private
136
+
137
+ def humanize secs
138
+ [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].inject([]){ |s, (count, name)|
139
+ if secs > 0
140
+ secs, n = secs.divmod(count)
141
+ s.unshift "#{n} #{name}"
142
+ end
143
+ s
144
+ }.join(' ')
145
+ end
146
+ end
147
+
148
+ end
149
+
150
+ CommandHistory = CommandHistoryImplementation.new
151
+
152
+ Yap::Shell::Execution::Context.on(:before_statements_execute) do |context|
153
+ puts "Before group: #{context.to_s}" if ENV["DEBUG"]
154
+ CommandHistory.start_group(Time.now)
155
+ end
156
+
157
+ Yap::Shell::Execution::Context.on(:after_statements_execute) do |context|
158
+ CommandHistory.stop_group(Time.now)
159
+ puts "After group: #{context.to_s}" if ENV["DEBUG"]
160
+ end
161
+
162
+ Yap::Shell::Execution::Context.on(:after_process_finished) do |context, *args|
163
+ # puts "After process: #{context.to_s}, args: #{args.inspect}"
164
+ end
165
+
166
+ Yap::Shell::Execution::Context.on(:before_execute) do |context, command:|
167
+ CommandHistory.push CommandHistoryImplementation::Item.new(command_str: command.str, started_at: Time.now)
168
+ end
169
+
170
+ Yap::Shell::Execution::Context.on(:after_execute) do |context, command:, result:|
171
+ CommandHistory.last_command.finished!
172
+ # if result.status_code == 0
173
+ # # t = TermInfo.new("xterm-color", STDOUT)
174
+ # # h, w = t.screen_size
175
+ # # t.control "cub", w
176
+ # # # msg =
177
+ # # t.control "cuf"
178
+ # # # t.control "home"
179
+ # #
180
+ # # # t.write "hi"
181
+ # # # t.control "rc"
182
+ # end
183
+ end
data/yap-shell.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yap/shell/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yap-shell"
8
+ spec.version = Yap::Shell::VERSION
9
+ spec.authors = ["Zach Dennis"]
10
+ spec.email = ["zach.dennis@gmail.com"]
11
+ spec.summary = %q{The Lagniappe "Yap" shell.}
12
+ spec.description = %q{The Lagniappe "Yap" shell.}
13
+ spec.homepage = "https://github.com/zdennis/yap-shell"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "yap-shell-parser", "~> 0.0.2"
22
+ spec.add_dependency "term-ansicolor", "~> 1.3"
23
+ spec.add_dependency "chronic", "~> 0.10"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 10"
27
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yap-shell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Zach Dennis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yap-shell-parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: term-ansicolor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chronic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10'
83
+ description: The Lagniappe "Yap" shell.
84
+ email:
85
+ - zach.dennis@gmail.com
86
+ executables:
87
+ - yap
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - DESIGN.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - WISHLIST.md
98
+ - bin/yap
99
+ - lib/tasks/gem.rake
100
+ - lib/yap.rb
101
+ - lib/yap/shell.rb
102
+ - lib/yap/shell/aliases.rb
103
+ - lib/yap/shell/builtins.rb
104
+ - lib/yap/shell/builtins/alias.rb
105
+ - lib/yap/shell/builtins/cd.rb
106
+ - lib/yap/shell/commands.rb
107
+ - lib/yap/shell/evaluation.rb
108
+ - lib/yap/shell/execution.rb
109
+ - lib/yap/shell/execution/builtin_command_execution.rb
110
+ - lib/yap/shell/execution/command_execution.rb
111
+ - lib/yap/shell/execution/context.rb
112
+ - lib/yap/shell/execution/file_system_command_execution.rb
113
+ - lib/yap/shell/execution/result.rb
114
+ - lib/yap/shell/execution/ruby_command_execution.rb
115
+ - lib/yap/shell/execution/shell_command_execution.rb
116
+ - lib/yap/shell/repl.rb
117
+ - lib/yap/shell/version.rb
118
+ - lib/yap/world.rb
119
+ - rcfiles/.yaprc
120
+ - yap-shell.gemspec
121
+ homepage: https://github.com/zdennis/yap-shell
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.3
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: The Lagniappe "Yap" shell.
145
+ test_files: []