yap-shell 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/WISHLIST.md +14 -0
- data/addons/history/Gemfile +2 -0
- data/addons/history/history.rb +101 -0
- data/addons/history/lib/history/buffer.rb +204 -0
- data/addons/history/lib/history/events.rb +13 -0
- data/addons/keyboard_macros/keyboard_macros.rb +295 -0
- data/addons/prompt/Gemfile +1 -0
- data/addons/prompt/right_prompt.rb +17 -0
- data/addons/prompt_updates/prompt_updates.rb +28 -0
- data/addons/tab_completion/Gemfile +0 -0
- data/addons/tab_completion/lib/tab_completion/completer.rb +62 -0
- data/addons/tab_completion/lib/tab_completion/custom_completion.rb +33 -0
- data/addons/tab_completion/lib/tab_completion/dsl_methods.rb +7 -0
- data/addons/tab_completion/lib/tab_completion/file_completion.rb +75 -0
- data/addons/tab_completion/tab_completion.rb +157 -0
- data/bin/yap +13 -4
- data/lib/tasks/addons.rake +51 -0
- data/lib/yap.rb +4 -55
- data/lib/yap/shell.rb +51 -10
- data/lib/yap/shell/builtins.rb +2 -2
- data/lib/yap/shell/builtins/alias.rb +2 -2
- data/lib/yap/shell/builtins/cd.rb +9 -11
- data/lib/yap/shell/builtins/env.rb +11 -0
- data/lib/yap/shell/commands.rb +29 -18
- data/lib/yap/shell/evaluation.rb +185 -68
- data/lib/yap/shell/evaluation/shell_expansions.rb +85 -0
- data/lib/yap/shell/event_emitter.rb +18 -0
- data/lib/yap/shell/execution/builtin_command_execution.rb +1 -1
- data/lib/yap/shell/execution/command_execution.rb +3 -3
- data/lib/yap/shell/execution/context.rb +32 -9
- data/lib/yap/shell/execution/file_system_command_execution.rb +12 -7
- data/lib/yap/shell/execution/ruby_command_execution.rb +6 -6
- data/lib/yap/shell/execution/shell_command_execution.rb +17 -2
- data/lib/yap/shell/prompt.rb +21 -0
- data/lib/yap/shell/repl.rb +179 -18
- data/lib/yap/shell/version.rb +1 -1
- data/lib/yap/world.rb +149 -15
- data/lib/yap/world/addons.rb +135 -0
- data/rcfiles/.yaprc +240 -10
- data/test.rb +206 -0
- data/update-rawline.sh +6 -0
- data/yap-shell.gemspec +11 -3
- metadata +101 -10
- data/addons/history.rb +0 -171
data/addons/history.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
module Yap
|
3
|
-
module WorldAddons
|
4
|
-
class History
|
5
|
-
def self.load
|
6
|
-
instance
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.instance
|
10
|
-
@history ||= History.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@history = []
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize_world(world)
|
18
|
-
load_history
|
19
|
-
|
20
|
-
world.func(:howmuch) do |args:, stdin:, stdout:, stderr:|
|
21
|
-
case args.first
|
22
|
-
when "time"
|
23
|
-
if history_item=self.last_executed_item
|
24
|
-
stdout.puts history_item.total_time_s
|
25
|
-
else
|
26
|
-
stdout.puts "Can't report on something you haven't done."
|
27
|
-
end
|
28
|
-
else
|
29
|
-
stdout.puts "How much what?"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def executing(command:, started_at:)
|
35
|
-
raise "Cannot acknowledge execution beginning of a command when no group has been started!" unless @history.last
|
36
|
-
@history.last.executing command:command, started_at:started_at
|
37
|
-
end
|
38
|
-
|
39
|
-
def executed(command:, stopped_at:)
|
40
|
-
raise "Cannot complete execution of a command when no group has been started!" unless @history.last
|
41
|
-
@history.last.executed command:command, stopped_at:stopped_at
|
42
|
-
end
|
43
|
-
|
44
|
-
def last_executed_item
|
45
|
-
@history.reverse.each do |group|
|
46
|
-
last_run = group.last_executed_item
|
47
|
-
break last_run if last_run
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def start_group(started_at)
|
52
|
-
@history.push Group.new(started_at:started_at)
|
53
|
-
end
|
54
|
-
|
55
|
-
def stop_group(stopped_at)
|
56
|
-
@history.last.stopped_at(stopped_at)
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def history_file
|
62
|
-
@history_file ||= File.expand_path('~') + '/.yap-history'
|
63
|
-
end
|
64
|
-
|
65
|
-
def load_history
|
66
|
-
return unless File.exists?(history_file) && File.readable?(history_file)
|
67
|
-
(YAML.load_file(history_file) || []).each do |item|
|
68
|
-
::Readline::HISTORY.push item
|
69
|
-
end
|
70
|
-
|
71
|
-
at_exit do
|
72
|
-
File.write history_file, ::Readline::HISTORY.to_a.to_yaml
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class Group
|
77
|
-
extend Forwardable
|
78
|
-
|
79
|
-
def initialize(started_at:Time.now)
|
80
|
-
@started_at = started_at
|
81
|
-
@stopped_at = nil
|
82
|
-
@items = []
|
83
|
-
end
|
84
|
-
|
85
|
-
def_delegators :@items, :push, :<<, :pop, :first, :last
|
86
|
-
|
87
|
-
def duration
|
88
|
-
return nil unless @stopped_at
|
89
|
-
@stopped_at - @started_at
|
90
|
-
end
|
91
|
-
|
92
|
-
def executing(command:, started_at:)
|
93
|
-
@items.push Item.new(command:command, started_at:started_at)
|
94
|
-
end
|
95
|
-
|
96
|
-
def executed(command:, stopped_at:)
|
97
|
-
raise "2:Cannot complete execution of a command when no group has been started!" unless @items.last
|
98
|
-
item = @items.reverse.detect do |item|
|
99
|
-
command == item.command && !item.finished?
|
100
|
-
end
|
101
|
-
item.finished!(stopped_at)
|
102
|
-
end
|
103
|
-
|
104
|
-
def last_executed_item
|
105
|
-
@items.reverse.detect{ |item| item.finished? }
|
106
|
-
end
|
107
|
-
|
108
|
-
def stopped_at(time)
|
109
|
-
@stopped_at ||= time
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
class Item
|
114
|
-
attr_reader :command
|
115
|
-
|
116
|
-
def initialize(command:command, started_at:Time.now)
|
117
|
-
@command = command
|
118
|
-
@started_at = started_at
|
119
|
-
@ended_at = nil
|
120
|
-
end
|
121
|
-
|
122
|
-
def finished!(at)
|
123
|
-
@ended_at = at
|
124
|
-
end
|
125
|
-
|
126
|
-
def finished?
|
127
|
-
!!@ended_at
|
128
|
-
end
|
129
|
-
|
130
|
-
def total_time_s
|
131
|
-
humanize(@ended_at - @started_at) if @ended_at && @started_at
|
132
|
-
end
|
133
|
-
|
134
|
-
private
|
135
|
-
|
136
|
-
def humanize secs
|
137
|
-
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].inject([]){ |s, (count, name)|
|
138
|
-
if secs > 0
|
139
|
-
secs, n = secs.divmod(count)
|
140
|
-
s.unshift "#{n} #{name}"
|
141
|
-
end
|
142
|
-
s
|
143
|
-
}.join(' ')
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
Yap::Shell::Execution::Context.on(:before_statements_execute) do |context|
|
148
|
-
puts "Before group: #{context.to_s}" if ENV["DEBUG"]
|
149
|
-
History.instance.start_group(Time.now)
|
150
|
-
end
|
151
|
-
|
152
|
-
Yap::Shell::Execution::Context.on(:after_statements_execute) do |context|
|
153
|
-
History.instance.stop_group(Time.now)
|
154
|
-
puts "After group: #{context.to_s}" if ENV["DEBUG"]
|
155
|
-
end
|
156
|
-
|
157
|
-
Yap::Shell::Execution::Context.on(:after_process_finished) do |context, *args|
|
158
|
-
# puts "After process: #{context.to_s}, args: #{args.inspect}"
|
159
|
-
end
|
160
|
-
|
161
|
-
Yap::Shell::Execution::Context.on(:before_execute) do |context, command:|
|
162
|
-
History.instance.executing command:command.str, started_at:Time.now
|
163
|
-
end
|
164
|
-
|
165
|
-
Yap::Shell::Execution::Context.on(:after_execute) do |context, command:, result:|
|
166
|
-
History.instance.executed command:command.str, stopped_at:Time.now
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|