yap-shell 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -24
- data/Gemfile +1 -5
- data/LICENSE.txt +17 -18
- data/README.md +28 -14
- data/Rakefile +4 -1
- data/bin/yap +1 -3
- data/lib/.gitkeep +0 -0
- data/yap-shell.gemspec +12 -11
- metadata +19 -184
- data/.rspec +0 -2
- data/.travis.yml +0 -11
- data/DESIGN.md +0 -87
- data/Gemfile.travis +0 -8
- data/Gemfile.travis.lock +0 -104
- data/WISHLIST.md +0 -54
- data/bin/yap-dev +0 -45
- data/lib/tasks/gem.rake +0 -62
- data/lib/yap.rb +0 -52
- data/lib/yap/addon.rb +0 -24
- data/lib/yap/addon/base.rb +0 -52
- data/lib/yap/addon/export_as.rb +0 -12
- data/lib/yap/addon/loader.rb +0 -84
- data/lib/yap/addon/path.rb +0 -56
- data/lib/yap/addon/rc_file.rb +0 -21
- data/lib/yap/addon/reference.rb +0 -22
- data/lib/yap/cli.rb +0 -4
- data/lib/yap/cli/commands.rb +0 -6
- data/lib/yap/cli/commands/addon.rb +0 -14
- data/lib/yap/cli/commands/addon/disable.rb +0 -35
- data/lib/yap/cli/commands/addon/enable.rb +0 -35
- data/lib/yap/cli/commands/addon/list.rb +0 -37
- data/lib/yap/cli/commands/addon/search.rb +0 -99
- data/lib/yap/cli/commands/generate.rb +0 -13
- data/lib/yap/cli/commands/generate/addon.rb +0 -258
- data/lib/yap/cli/commands/generate/addonrb.template +0 -22
- data/lib/yap/cli/commands/generate/gemspec.template +0 -25
- data/lib/yap/cli/commands/generate/license.template +0 -21
- data/lib/yap/cli/commands/generate/rakefile.template +0 -6
- data/lib/yap/cli/commands/generate/readme.template +0 -40
- data/lib/yap/cli/options.rb +0 -162
- data/lib/yap/cli/options/addon.rb +0 -64
- data/lib/yap/cli/options/addon/disable.rb +0 -62
- data/lib/yap/cli/options/addon/enable.rb +0 -63
- data/lib/yap/cli/options/addon/list.rb +0 -65
- data/lib/yap/cli/options/addon/search.rb +0 -76
- data/lib/yap/cli/options/generate.rb +0 -59
- data/lib/yap/cli/options/generate/addon.rb +0 -63
- data/lib/yap/configuration.rb +0 -74
- data/lib/yap/gem_helper.rb +0 -195
- data/lib/yap/gem_tasks.rb +0 -6
- data/lib/yap/shell.rb +0 -116
- data/lib/yap/shell/aliases.rb +0 -58
- data/lib/yap/shell/builtins.rb +0 -18
- data/lib/yap/shell/builtins/alias.rb +0 -42
- data/lib/yap/shell/builtins/cd.rb +0 -57
- data/lib/yap/shell/builtins/env.rb +0 -11
- data/lib/yap/shell/commands.rb +0 -163
- data/lib/yap/shell/evaluation.rb +0 -439
- data/lib/yap/shell/evaluation/shell_expansions.rb +0 -99
- data/lib/yap/shell/event_emitter.rb +0 -18
- data/lib/yap/shell/execution.rb +0 -16
- data/lib/yap/shell/execution/builtin_command_execution.rb +0 -20
- data/lib/yap/shell/execution/command_execution.rb +0 -30
- data/lib/yap/shell/execution/context.rb +0 -128
- data/lib/yap/shell/execution/file_system_command_execution.rb +0 -137
- data/lib/yap/shell/execution/result.rb +0 -18
- data/lib/yap/shell/execution/ruby_command_execution.rb +0 -80
- data/lib/yap/shell/execution/shell_command_execution.rb +0 -30
- data/lib/yap/shell/prompt.rb +0 -21
- data/lib/yap/shell/repl.rb +0 -237
- data/lib/yap/shell/version.rb +0 -5
- data/lib/yap/world.rb +0 -286
- data/rcfiles/yaprc +0 -390
- data/scripts/4 +0 -8
- data/scripts/bg-vim +0 -4
- data/scripts/fail +0 -3
- data/scripts/letters +0 -8
- data/scripts/lots-of-output +0 -6
- data/scripts/pass +0 -3
- data/scripts/simulate-long-running +0 -4
- data/scripts/write-to-stderr.rb +0 -3
- data/scripts/write-to-stdout.rb +0 -3
- data/spec/features/addons/generating_an_addon_spec.rb +0 -55
- data/spec/features/addons/using_an_addon_spec.rb +0 -182
- data/spec/features/aliases_spec.rb +0 -78
- data/spec/features/environment_variables_spec.rb +0 -69
- data/spec/features/filesystem_commands_spec.rb +0 -61
- data/spec/features/first_time_spec.rb +0 -45
- data/spec/features/grouping_spec.rb +0 -81
- data/spec/features/line_editing_spec.rb +0 -174
- data/spec/features/range_spec.rb +0 -35
- data/spec/features/redirection_spec.rb +0 -234
- data/spec/features/repetition_spec.rb +0 -118
- data/spec/features/shell_expansions_spec.rb +0 -127
- data/spec/spec_helper.rb +0 -172
- data/spec/support/matchers/have_not_printed.rb +0 -30
- data/spec/support/matchers/have_printed.rb +0 -68
- data/spec/support/very_soon.rb +0 -9
- data/spec/support/yap_spec_dsl.rb +0 -258
- data/test.rb +0 -206
- data/update-rawline.sh +0 -6
data/rcfiles/yaprc
DELETED
@@ -1,390 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
# world.addons[:'keyboard-macros'].disable!
|
4
|
-
|
5
|
-
old_world_envs = []
|
6
|
-
parse_env_vars_from_string = -> (str) {
|
7
|
-
keys_and_values = str.split("\n").map(&:chomp).map do |line|
|
8
|
-
next if line =~ /^\s*#/
|
9
|
-
line.split('=', 2)
|
10
|
-
end.compact
|
11
|
-
|
12
|
-
keys_and_values.map! do |(key, value)|
|
13
|
-
if value =~ /^['"]/
|
14
|
-
[key, value.scan(/^['"](.*)['"]\s*$/).flatten.first]
|
15
|
-
else
|
16
|
-
[key, value]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
}
|
20
|
-
|
21
|
-
load_dotenv_file = -> (file) {
|
22
|
-
dotenv_file = Dir[file].first
|
23
|
-
if dotenv_file
|
24
|
-
old_world_envs.push world.env.dup
|
25
|
-
Treefell['shell'].puts "loading dotenv file #{dotenv_file}"
|
26
|
-
keys_and_values = parse_env_vars_from_string.call(IO.read(dotenv_file))
|
27
|
-
|
28
|
-
keys_and_values.each do |(key, value)|
|
29
|
-
next unless key
|
30
|
-
next if key == 'RAILS_ENV'
|
31
|
-
world.env[key] = value
|
32
|
-
end
|
33
|
-
Treefell['shell'].puts "done loading dotenv"
|
34
|
-
end
|
35
|
-
}
|
36
|
-
|
37
|
-
|
38
|
-
Yap::Shell::Execution::Context.on(:after_execute) do |world, command:, **kwargs|
|
39
|
-
if command.str == "nvm"
|
40
|
-
old_nvm_bin = world.env["NVM_BIN"]
|
41
|
-
Dir[ world.configuration.path_for("env/nvm.env") ].each do |file|
|
42
|
-
if old_nvm_bin
|
43
|
-
world.env["PATH"].sub!(/#{Regexp.escape(old_nvm_bin)}:/, '')
|
44
|
-
end
|
45
|
-
|
46
|
-
key_and_values = parse_env_vars_from_string.call(IO.read(file))
|
47
|
-
key_and_values.each do |(key, value)|
|
48
|
-
world.env[key] = value
|
49
|
-
end
|
50
|
-
|
51
|
-
nvm_bin = world.env["NVM_BIN"]
|
52
|
-
if nvm_bin
|
53
|
-
world.env["PATH"] = nvm_bin + ":" + world.env["PATH"]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
Yap::Shell::Execution::Context.on(:before_execute) do |world, command:|
|
60
|
-
if command.str == "cd"
|
61
|
-
if old_world_envs.any?
|
62
|
-
world.env.replace(old_world_envs.first)
|
63
|
-
old_world_envs.clear
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
Yap::Shell::Execution::Context.on(:after_execute) do |world, command:, result:|
|
69
|
-
if command.str == "cd"
|
70
|
-
load_dotenv_file.call('.env')
|
71
|
-
load_dotenv_file.call('.env.local')
|
72
|
-
rails_env = world.env['RAILS_ENV']
|
73
|
-
if rails_env
|
74
|
-
load_dotenv_file.call(".env.#{rails_env}")
|
75
|
-
else
|
76
|
-
load_dotenv_file.call(".env.development")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
###############################################################################
|
82
|
-
# ENVIRONMENT VARIABLES
|
83
|
-
#------------------------------------------------------------------------------
|
84
|
-
# When yap boots up it constructs a world for the running shell. The world
|
85
|
-
# has it's own copy of environment variables. Below is an example of
|
86
|
-
# modifying your PATH environment variables.
|
87
|
-
world.env["PATH"] = [
|
88
|
-
world.env["HOME"] + "/.rbenv/shims",
|
89
|
-
"/usr/local/bin",
|
90
|
-
world.env["PATH"]
|
91
|
-
].join(":")
|
92
|
-
|
93
|
-
|
94
|
-
###############################################################################
|
95
|
-
# SHELL HISTORY
|
96
|
-
#------------------------------------------------------------------------------
|
97
|
-
# Here's an example of resizing shell history to be of infinite size. If you
|
98
|
-
# set this to a numeric value then it will only maintain that many entries.
|
99
|
-
infinity = 1 / 0.0
|
100
|
-
world.history.resize(infinity)
|
101
|
-
|
102
|
-
func :reload! do |args:, stdin:, stdout:, stderr:|
|
103
|
-
stdout.puts "Reloading shell:"
|
104
|
-
stdout.print " Saving history "
|
105
|
-
world.addons[:history].save
|
106
|
-
stdout.puts Term::ANSIColor.green("done")
|
107
|
-
world.reload!
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
###############################################################################
|
112
|
-
# CONFIGURING YOUR PROMPT
|
113
|
-
#------------------------------------------------------------------------------
|
114
|
-
# Your prompt can be whatever you can code it to be. It can be static or
|
115
|
-
# or dynamic. You can also update the prompt indirectly so that it live
|
116
|
-
# updates regardless of if you hit enter.
|
117
|
-
#
|
118
|
-
# The easiest thing to do is to set the prompt to a static string, but it's
|
119
|
-
# also the least useful way to utilize your prompt, e.g.:
|
120
|
-
#
|
121
|
-
# yap> world.prompt = 'my-prompt>'
|
122
|
-
#
|
123
|
-
# A more useful way to configure your prompt is by using a lambda/proc (or
|
124
|
-
# anything that responds to 'call'). This proc will be called whenever
|
125
|
-
# the prompt needs to be rendered, so it can be as dynamic as you like. Below
|
126
|
-
# is an example of setting a prompt with a bunch of git smarts.
|
127
|
-
#
|
128
|
-
# One other thing worth noting is that you can re-render the prompt without
|
129
|
-
# having to hit enter to run a statement. If this piques your interest check
|
130
|
-
# out the prompt_updates/ addon included in the yap-shell gem. It's in the
|
131
|
-
# YAP_SHELL_INSTALL_DIR/addons/promp_updates/ directory.
|
132
|
-
#
|
133
|
-
# Now, here's an example of a smart prompt with some git intelligence:
|
134
|
-
|
135
|
-
world.prompt = -> do
|
136
|
-
# use ~ instead of full-path to home directory
|
137
|
-
pwd = Dir.pwd.sub Regexp.new(ENV['HOME']), '~'
|
138
|
-
|
139
|
-
# identify our current branch
|
140
|
-
git_current_branch = `git branch 2>/dev/null | sed -n '/\* /s///p'`.chomp
|
141
|
-
|
142
|
-
# is the current directory a part of a git enabled directory structure?
|
143
|
-
current_dir_is_git_aware = git_current_branch.length > 0
|
144
|
-
|
145
|
-
if current_dir_is_git_aware
|
146
|
-
git_current_branch += " "
|
147
|
-
|
148
|
-
# are there unstaged changes?
|
149
|
-
git_dirty_not_cached = `git diff --shortstat 2>/dev/null`.length > 0
|
150
|
-
|
151
|
-
# are there staged changes?
|
152
|
-
git_dirty_cached = `git diff --shortstat --cached 2>/dev/null`.length > 0
|
153
|
-
|
154
|
-
if git_dirty_not_cached || git_dirty_cached
|
155
|
-
# uncommitted changes
|
156
|
-
git_branch = intense_cyan(git_current_branch)
|
157
|
-
else
|
158
|
-
# no uncommitted changes
|
159
|
-
git_branch = cyan(git_current_branch)
|
160
|
-
end
|
161
|
-
else
|
162
|
-
git_branch = ""
|
163
|
-
end
|
164
|
-
|
165
|
-
# Example: ~/source/playground/yap master ➜
|
166
|
-
"#{yellow(pwd)} #{git_branch}#{red('➜')} "
|
167
|
-
end
|
168
|
-
|
169
|
-
###############################################################################
|
170
|
-
# SECONDARY PROMPT
|
171
|
-
#------------------------------------------------------------------------------
|
172
|
-
# The secondary_prompt is equivalent to the PS2 prompt in bash. It is what
|
173
|
-
# is displayed when entering a multiline command. It can be set to a string
|
174
|
-
# or a proc. It defaults to '> '
|
175
|
-
#
|
176
|
-
# To see it in action, type "echo 'foo" with no completing single quote and
|
177
|
-
# hit enter.
|
178
|
-
self.secondary_prompt = '> '
|
179
|
-
|
180
|
-
###############################################################################
|
181
|
-
# KEYBOARD MACROS
|
182
|
-
#------------------------------------------------------------------------------
|
183
|
-
# Keyboard macros allow you to define key/byte sequences that run code
|
184
|
-
# when typed. Perhaps the simpest macro is one that takes the tediousness
|
185
|
-
# out of typing a long command. For example, pressing "Ctrl-g l" might
|
186
|
-
# type in "git log --name-status -n100" just as if the user had typed it.
|
187
|
-
#
|
188
|
-
# There are five things to know about macros in Yap:
|
189
|
-
#
|
190
|
-
# * Macros are initialized by a trigger key. The default is Ctrl-g.
|
191
|
-
# * Macros require at least one character/key/byte sequence beyond the trigger \
|
192
|
-
# key in order to fire
|
193
|
-
# * Macros can be bound to code blocks or a string.
|
194
|
-
# * When a macro returns a string that string is inserted as user input \
|
195
|
-
# at the current cursor position
|
196
|
-
# * When a macro returns a string that ends in a new line it will process the \
|
197
|
-
# line as if the user hit enter
|
198
|
-
#
|
199
|
-
# == Example
|
200
|
-
#
|
201
|
-
# world.addons[:'keyboard-macros'].configure(trigger_key: :ctrl_g) do |macros|
|
202
|
-
# macros.define :z, 'git open-pull'
|
203
|
-
# macros.define 'l', "git log -n1\n"
|
204
|
-
# end
|
205
|
-
#
|
206
|
-
# It's a little bit wordy right now to setup because macros are not special
|
207
|
-
# in Yap. They are provided as a standard yap-addon. You could even provide
|
208
|
-
# your own macro addon replacement if you so desired.
|
209
|
-
#
|
210
|
-
# Following, are a few examples showcasing macros.
|
211
|
-
###############################################################################
|
212
|
-
|
213
|
-
# Sets the default trigger key for all keyboard macros
|
214
|
-
world.addons[:'keyboard-macros'].trigger_key = ?\C-g
|
215
|
-
|
216
|
-
# Sets the default cancel key (space) for all keyboard macros
|
217
|
-
world.addons[:'keyboard-macros'].cancel_key = " "
|
218
|
-
|
219
|
-
# Sets the default timeout for macros. When set to nil you will have to
|
220
|
-
# use the cancel key to exit out of macros.
|
221
|
-
world.addons[:'keyboard-macros'].timeout_in_ms = nil
|
222
|
-
|
223
|
-
# Forgiveness-mode: Automatically cancel if the sequence is unknown. When
|
224
|
-
# set to false you can keep attempting to type in your macro.
|
225
|
-
world.addons[:'keyboard-macros'].cancel_on_unknown_sequences = true
|
226
|
-
|
227
|
-
keyboard_macros = world.addons[:'keyboard-macros']
|
228
|
-
keyboard_macros.cycle(:recent_git_branches) { `git recent`.lines.map(&:chomp) }
|
229
|
-
world.editor.bind(:alt_up_arrow) do
|
230
|
-
keyboard_macros.cycle(:recent_git_branches).next
|
231
|
-
end
|
232
|
-
world.editor.bind(:alt_down_arrow) do
|
233
|
-
keyboard_macros.cycle(:recent_git_branches).previous
|
234
|
-
end
|
235
|
-
|
236
|
-
world.editor.bind(:ctrl_r) do
|
237
|
-
world.addons[:'history-search'].prompt_user_to_search
|
238
|
-
end
|
239
|
-
|
240
|
-
# Or, you can set the trigger key for a particular set of macros
|
241
|
-
# by specifying it when you call .configure(...).
|
242
|
-
world.addons[:'keyboard-macros'].configure(trigger_key: ?\C-g) do |macro|
|
243
|
-
macro.start do
|
244
|
-
# TODO: FUTURE
|
245
|
-
# world.editor.content_box.children = [
|
246
|
-
# TerminalLayout::Box.new(content: "am i floating1?", style: {display: :float, float: :right, height: 1, width: "am i floating1?".length}),
|
247
|
-
# TerminalLayout::Box.new(content: "What up12?", style: {display: :block}),
|
248
|
-
# TerminalLayout::Box.new(content: "Not much21", style: {display: :block}),
|
249
|
-
# TerminalLayout::Box.new(content: "am i floating3?", style: {display: :float, float: :left, height: 1, width: "am i floating1?".length}),
|
250
|
-
# ]
|
251
|
-
end
|
252
|
-
|
253
|
-
macro.stop do
|
254
|
-
world.editor.content_box.children = []
|
255
|
-
end
|
256
|
-
|
257
|
-
macro.define 'z', "git open-pull\n"
|
258
|
-
macro.define 'abc', 'echo abc'
|
259
|
-
macro.define 'u', -> { world.editor.undo }
|
260
|
-
|
261
|
-
macro.define 'b' do |macro|
|
262
|
-
macro.start { macro.cycle(:recent_git_branches).reset }
|
263
|
-
|
264
|
-
macro.cycle(:recent_git_branches) { `git recent`.lines.map(&:chomp) }
|
265
|
-
macro.fragment :up_arrow, -> { macro.cycle(:recent_git_branches).next }
|
266
|
-
macro.fragment :down_arrow, -> { macro.cycle(:recent_git_branches).previous }
|
267
|
-
end
|
268
|
-
|
269
|
-
macro.define 'l', 'git log ' do |macro|
|
270
|
-
macro.fragment 'n', '--name-status '
|
271
|
-
macro.fragment 'm', 'master..HEAD '
|
272
|
-
macro.fragment 'o', '--oneline '
|
273
|
-
macro.fragment /\d/, -> (a) { "-n#{a} " }
|
274
|
-
end
|
275
|
-
|
276
|
-
macro.define 'd', 'git diff ' do |macro|
|
277
|
-
macro.fragment 'n', '--name-status '
|
278
|
-
macro.fragment 'm', 'master..HEAD '
|
279
|
-
macro.fragment 'o', '--oneline '
|
280
|
-
macro.fragment /\d/, -> (a) { "-n#{a} " }
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
# The below macro shows that you can have macros start with a different
|
285
|
-
# trigger keys.
|
286
|
-
# world.addons[:'keyboard-macros'].configure(trigger_key: :ctrl_h) do |macros|
|
287
|
-
# macros.define 'h123', -> {
|
288
|
-
# box = TerminalLayout::Box.new(content: "Right?", style: { display: :block, float: :right, height: 1, width: 50 })
|
289
|
-
# world.editor.content_box.children = [box]
|
290
|
-
# 'echo this was with a code block'
|
291
|
-
# }
|
292
|
-
# end
|
293
|
-
|
294
|
-
|
295
|
-
###############################################################################
|
296
|
-
# USER-DEFINED FUNCTIONS
|
297
|
-
#------------------------------------------------------------------------------
|
298
|
-
# User-defined functions can be accessed in the shell like any command. They
|
299
|
-
# take precedence over programs found on the file-system, but they do not
|
300
|
-
# take precedent over user-defined aliases.
|
301
|
-
#
|
302
|
-
# For example, take `upcase` below:
|
303
|
-
#
|
304
|
-
# func :upcase do |stdin:, stdout:|
|
305
|
-
# str = stdin.read
|
306
|
-
# stdout.puts str.upcase
|
307
|
-
# end
|
308
|
-
#
|
309
|
-
# You can issue "upcase" in the shell where-ever you'd expect to place the name
|
310
|
-
# of a command.
|
311
|
-
#
|
312
|
-
# == Function Parameters
|
313
|
-
#
|
314
|
-
# User-defined functions can receive the following arguments:
|
315
|
-
#
|
316
|
-
# * command: the name of the command the user-entered
|
317
|
-
# * args: the list of arguments supplied to the command
|
318
|
-
# * stdin: the way to access stdin (e.g. DO NOT CALL STDIN or $stdin)
|
319
|
-
# * stdout: the way to access stdout (e.g. DO NOT CALL STDOUT or $stdout)
|
320
|
-
# * stderr: the way to access stderr (e.g. DO NOT CALL STDERR or $stderr)
|
321
|
-
# * world: the Shell's currently known world
|
322
|
-
#
|
323
|
-
# These arguments are all optional. You only need to specify what your
|
324
|
-
# function is going to use.
|
325
|
-
#
|
326
|
-
# Following, are a number of examples showcasing their power and flexibility.
|
327
|
-
###############################################################################
|
328
|
-
|
329
|
-
# upcase is reads from stdin and upcases every letter.
|
330
|
-
#
|
331
|
-
# Example:
|
332
|
-
# yap> echo "hi there" | upcase
|
333
|
-
# HI THERE
|
334
|
-
func :upcase do |stdin:, stdout:|
|
335
|
-
str = stdin.read
|
336
|
-
stdout.puts str.upcase
|
337
|
-
end
|
338
|
-
|
339
|
-
func :'run-modified-specs' do |stdin:, stdout:|
|
340
|
-
str = `git status`
|
341
|
-
files = str.scan(/\S+.rb/)
|
342
|
-
specs, non_specs = files.partition { |file| file.match(/\S+_spec.rb/) }
|
343
|
-
non_specs.each do |non_spec|
|
344
|
-
filename_without_extension = non_spec.gsub(/^[^\/]+\//, '').gsub(/\.rb$/, '')
|
345
|
-
specs.concat Dir["spec/**/*#{filename_without_extension}_spec.rb"]
|
346
|
-
end
|
347
|
-
|
348
|
-
cmd = "bundle exec rspec #{specs.join(' ')}"
|
349
|
-
stdout.puts cmd
|
350
|
-
shell cmd
|
351
|
-
end
|
352
|
-
|
353
|
-
# This shell function uses a Regexp to match on a command of 2 or more dots.
|
354
|
-
# It's for traversing up N directories. Two dots ("..") is the minimum and
|
355
|
-
# is used to go to the parent. Every dot after that goes up one more directory
|
356
|
-
# level.
|
357
|
-
#
|
358
|
-
# Example:
|
359
|
-
# ~/foo/bar/baz> ..
|
360
|
-
# ~/foo/bar> ...
|
361
|
-
# ~/
|
362
|
-
func /^\.{2,}$/ do |command:|
|
363
|
-
(command.length - 1).times { Dir.chdir("..") }
|
364
|
-
end
|
365
|
-
|
366
|
-
func /^\+(.*)/ do |command:, args:|
|
367
|
-
puts command
|
368
|
-
puts args.inspect
|
369
|
-
end
|
370
|
-
|
371
|
-
# This shell function uses a custom object that responds to the #match(...)
|
372
|
-
# method. This is nothing more than an basic "history" implementation.
|
373
|
-
#
|
374
|
-
history_matcher = Object.new
|
375
|
-
def history_matcher.match(command)
|
376
|
-
command == ".h"
|
377
|
-
end
|
378
|
-
|
379
|
-
# Allows for a single numeric argument which will be used to determine
|
380
|
-
# how many history items to show (not including this command). If no argument
|
381
|
-
# if provided then it will show the entire shell history.
|
382
|
-
func history_matcher do |world:, args:, stdout:|
|
383
|
-
num_commands = args.first.to_i
|
384
|
-
num_commands = world.history.length - 1 if num_commands == 0
|
385
|
-
history_size = world.history.length
|
386
|
-
world.history[-(num_commands + 1)...-1].each_with_index do |command, i|
|
387
|
-
position = history_size - num_commands + i
|
388
|
-
stdout.puts " #{position} #{command}"
|
389
|
-
end
|
390
|
-
end
|
data/scripts/4
DELETED
data/scripts/bg-vim
DELETED
data/scripts/fail
DELETED
data/scripts/letters
DELETED
data/scripts/lots-of-output
DELETED
data/scripts/pass
DELETED
data/scripts/write-to-stderr.rb
DELETED
data/scripts/write-to-stdout.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Generating an addon', type: :feature, repl: false do
|
4
|
-
let(:addons_path) { tmp_dir.join('addons/') }
|
5
|
-
let(:yaprc_path) { tmp_dir.join('yaprc') }
|
6
|
-
let(:yaprc_contents) { '' }
|
7
|
-
|
8
|
-
let(:yap_cli_args) do
|
9
|
-
[
|
10
|
-
'generate', 'addon', 'foo-bar'
|
11
|
-
]
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
set_yap_command_line_arguments yap_cli_args
|
16
|
-
|
17
|
-
turn_on_debug_log(debug: 'editor')
|
18
|
-
|
19
|
-
reinitialize_shell
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'generates an addon in the current working directory' do
|
23
|
-
# foo-addon is a shell function added by the foo-addon defined above;
|
24
|
-
expect { output }.to have_printed_lines <<-TEXT.gsub(/^\s*\|/, '')
|
25
|
-
|Creating addon foo-bar in yap-shell-addon-foo-bar/
|
26
|
-
|
|
27
|
-
|Create directory: yap-shell-addon-foo-bar done
|
28
|
-
|Create directory: lib done
|
29
|
-
|Creating file: Gemfile done
|
30
|
-
|Creating file: yap-shell-addon-foo-bar.gemspec done
|
31
|
-
|Creating file: LICENSE.txt done
|
32
|
-
|Creating file: Rakefile done
|
33
|
-
|Creating file: README.md done
|
34
|
-
|Creating file: lib/yap-shell-addon-foo-bar.rb done
|
35
|
-
|Create directory: lib/yap-shell-addon-foo-bar done
|
36
|
-
|Creating file: lib/yap-shell-addon-foo-bar/version.rb done
|
37
|
-
|
|
38
|
-
|Creating file: .gitignore done
|
39
|
-
|git init . && git add . && git commit -m 'initial commit of foo-bar' done
|
40
|
-
|
|
41
|
-
|Yap addon generated! A few helpful things to note:
|
42
|
-
|
|
43
|
-
| * The foo-bar addon has been generated in yap-shell-addon-foo-bar/
|
44
|
-
| * It is a standard rubygem, has its own gemspec, and is named yap-shell-addon-foo-bar
|
45
|
-
| * Yap loads the YapShellAddonFooBar, found in lib/yap-shell-addon-foo-bar.rb (start there)
|
46
|
-
| * Share your addon with others by building a gem and pushing it to rubygems
|
47
|
-
|
48
|
-
|For more information see https://github.com/zdennis/yap-shell/wiki/Addons
|
49
|
-
|
|
50
|
-
|Now, to get started:
|
51
|
-
|
|
52
|
-
| cd yap-shell-addon-foo-bar
|
53
|
-
TEXT
|
54
|
-
end
|
55
|
-
end
|