yap-shell 0.4.6 → 0.4.8
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.
- checksums.yaml +4 -4
- data/addons/tab_completion/tab_completion.rb +3 -3
- data/lib/yap/configuration.rb +9 -1
- data/lib/yap/shell/repl.rb +5 -2
- data/lib/yap/shell/version.rb +1 -1
- data/lib/yap/world.rb +24 -1
- data/rcfiles/{.yaprc → yaprc} +62 -44
- data/yap-shell.gemspec +5 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a31682029b9cbd355da08f48de73df26f18ac7e3
|
4
|
+
data.tar.gz: 11cac119d25dc8a0b19037c128cd7c08992449d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73674732a59260cf427392a8cc6617bb0d78a602dc2c49f8c5a588d2e952805a0d0bb51fa086961a7d938d411f4c76f12874a44085a6748d5e4db06ae3c49ec8
|
7
|
+
data.tar.gz: fa6f4ee6f68e5c426a36ebe600be7a158cf3bfccc448694299af5cf4569a77753b13d735c87058489ad1740a27503c6381faee10369bce92f28829ba286b021e
|
data/lib/yap/configuration.rb
CHANGED
@@ -19,7 +19,7 @@ module Yap
|
|
19
19
|
|
20
20
|
@rcfiles = [
|
21
21
|
"#{ENV['HOME']}/.yaprc",
|
22
|
-
|
22
|
+
preferred_yaprc_path
|
23
23
|
]
|
24
24
|
end
|
25
25
|
|
@@ -27,6 +27,14 @@ module Yap
|
|
27
27
|
yap_path.join(part)
|
28
28
|
end
|
29
29
|
|
30
|
+
def preferred_yaprc_path
|
31
|
+
yap_path.join("yaprc")
|
32
|
+
end
|
33
|
+
|
34
|
+
def yaprc_template_path
|
35
|
+
Pathname.new(File.dirname(__FILE__)).join('../../rcfiles/yaprc')
|
36
|
+
end
|
37
|
+
|
30
38
|
def yap_path
|
31
39
|
Pathname.new "#{ENV['HOME']}/.yap"
|
32
40
|
end
|
data/lib/yap/shell/repl.rb
CHANGED
@@ -34,8 +34,11 @@ module Yap::Shell
|
|
34
34
|
rescue Yap::Shell::Parser::Lexer::NonterminatedString,
|
35
35
|
Yap::Shell::Parser::Lexer::LineContinuationFound => ex
|
36
36
|
Treefell['shell'].puts "rescued #{ex}, asking user for more input"
|
37
|
-
|
38
|
-
|
37
|
+
more_input = read_another_line_of_input
|
38
|
+
if more_input
|
39
|
+
line << more_input
|
40
|
+
retry
|
41
|
+
end
|
39
42
|
rescue ::Yap::Shell::CommandUnknownError => ex
|
40
43
|
Treefell['shell'].puts "rescued #{ex}, telling user"
|
41
44
|
puts " CommandError: #{ex.message}"
|
data/lib/yap/shell/version.rb
CHANGED
data/lib/yap/world.rb
CHANGED
@@ -32,7 +32,26 @@ module Yap
|
|
32
32
|
dom = build_editor_dom
|
33
33
|
|
34
34
|
# ensure yap directory exists
|
35
|
-
|
35
|
+
if !File.exists?(configuration.yap_path)
|
36
|
+
puts
|
37
|
+
puts yellow("Yap directory not found: #{configuration.yap_path}")
|
38
|
+
puts
|
39
|
+
puts "Initializing yap for the first time:"
|
40
|
+
puts
|
41
|
+
|
42
|
+
print " Creating #{configuration.yap_path} "
|
43
|
+
FileUtils.mkdir_p configuration.yap_path
|
44
|
+
puts green("done")
|
45
|
+
|
46
|
+
print " Creating default #{configuration.preferred_yaprc_path} "
|
47
|
+
FileUtils.cp configuration.yaprc_template_path, configuration.yap_path
|
48
|
+
puts green("done")
|
49
|
+
puts
|
50
|
+
puts "To tweak yap take a look at #{configuration.preferred_yaprc_path}."
|
51
|
+
puts
|
52
|
+
puts "Reloading shell"
|
53
|
+
reload!
|
54
|
+
end
|
36
55
|
|
37
56
|
@editor = RawLine::Editor.create(dom: dom)
|
38
57
|
|
@@ -84,6 +103,10 @@ module Yap
|
|
84
103
|
@editor.unbind(key)
|
85
104
|
end
|
86
105
|
|
106
|
+
def reload!
|
107
|
+
exec File.expand_path($0)
|
108
|
+
end
|
109
|
+
|
87
110
|
def func(name, &blk)
|
88
111
|
Yap::Shell::ShellCommand.define_shell_function(name, &blk)
|
89
112
|
end
|
data/rcfiles/{.yaprc → yaprc}
RENAMED
@@ -1,16 +1,23 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
###############################################################################
|
4
|
+
# ENVIRONMENT VARIABLES
|
5
|
+
#------------------------------------------------------------------------------
|
6
|
+
# When yap boots up it constructs a world for the running shell. The world
|
7
|
+
# has it's own copy of environment variables. Below is an example of
|
8
|
+
# modifying your PATH environment variables.
|
3
9
|
world.env["PATH"] = [
|
4
10
|
world.env["HOME"] + "/.rbenv/shims",
|
5
11
|
"/usr/local/bin",
|
6
12
|
world.env["PATH"]
|
7
13
|
].join(":")
|
8
14
|
|
9
|
-
require 'chronic'
|
10
|
-
require 'term/ansicolor'
|
11
|
-
require 'terminfo'
|
12
15
|
|
13
|
-
|
16
|
+
###############################################################################
|
17
|
+
# SHELL HISTORY
|
18
|
+
#------------------------------------------------------------------------------
|
19
|
+
# Here's an example of resizing shell history to be of infinite size. If you
|
20
|
+
# set this to a numeric value then it will only maintain that many entries.
|
14
21
|
infinity = 1 / 0.0
|
15
22
|
world.history.resize(infinity)
|
16
23
|
|
@@ -19,63 +26,71 @@ func :reload! do |args:, stdin:, stdout:, stderr:|
|
|
19
26
|
stdout.print " Saving history "
|
20
27
|
world.addons[:history].save
|
21
28
|
stdout.puts Term::ANSIColor.green("done")
|
22
|
-
|
29
|
+
world.reload!
|
23
30
|
end
|
24
31
|
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
33
|
+
###############################################################################
|
34
|
+
# CONFIGURING YOUR PROMPT
|
35
|
+
#------------------------------------------------------------------------------
|
36
|
+
# Your prompt can be whatever you can code it to be. It can be static or
|
37
|
+
# or dynamic. You can also update the prompt indirectly so that it live
|
38
|
+
# updates regardless of if you hit enter.
|
29
39
|
#
|
30
|
-
#
|
31
|
-
|
32
|
-
tab_completion :rake, /^(rake|be rake)\s+(.*)/ do |input_fragment, match_data|
|
33
|
-
# |config|
|
34
|
-
# config.completions do |input_fragment, match_data|
|
35
|
-
results = completion_cache[Dir.pwd] ||= `bundle exec rake -T`.gsub(/^rake\s*/, '').split(/\n/)
|
36
|
-
|
37
|
-
task_rgx = /^#{Regexp.escape(input_fragment.word[:text])}/
|
38
|
-
results.grep(task_rgx).map do |text|
|
39
|
-
{
|
40
|
-
type: :rake,
|
41
|
-
text: text.gsub(/\s*#.*$/, ''),
|
42
|
-
descriptive_text: Term::ANSIColor.yellow(text)
|
43
|
-
}
|
44
|
-
# end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
40
|
+
# The easiest thing to do is to set the prompt to a static string, but it's
|
41
|
+
# also the least useful way to utilize your prompt, e.g.:
|
48
42
|
#
|
49
|
-
#
|
50
|
-
# Proc like object that responds to #call. If it responds to call it will
|
51
|
-
# be used every time the prompt is to be re-drawn
|
43
|
+
# yap> world.prompt = 'my-prompt>'
|
52
44
|
#
|
53
|
-
|
54
|
-
|
45
|
+
# A more useful way to configure your prompt is by using a lambda/proc (or
|
46
|
+
# anything that responds to 'call'). This proc will be called whenever
|
47
|
+
# the prompt needs to be rendered, so it can be as dynamic as you like. Below
|
48
|
+
# is an example of setting a prompt with a bunch of git smarts.
|
49
|
+
#
|
50
|
+
# One other thing worth noting is that you can re-render the prompt without
|
51
|
+
# having to hit enter to run a statement. If this piques your interest check
|
52
|
+
# out the prompt_updates/ addon included in the yap-shell gem. It's in the
|
53
|
+
# YAP_SHELL_INSTALL_DIR/addons/promp_updates/ directory.
|
54
|
+
#
|
55
|
+
# Now, here's an example of a smart prompt with some git intelligence:
|
56
|
+
|
57
|
+
world.prompt = -> do
|
58
|
+
# use ~ instead of full-path to home directory
|
55
59
|
pwd = Dir.pwd.sub Regexp.new(ENV['HOME']), '~'
|
56
60
|
|
61
|
+
# identify our current branch
|
57
62
|
git_current_branch = `git branch 2>/dev/null | sed -n '/\* /s///p'`.chomp
|
58
|
-
|
63
|
+
|
64
|
+
# is the current directory a part of a git enabled directory structure?
|
65
|
+
current_dir_is_git_aware = git_current_branch.length > 0
|
66
|
+
|
67
|
+
if current_dir_is_git_aware
|
59
68
|
git_current_branch += " "
|
69
|
+
|
70
|
+
# are there unstaged changes?
|
60
71
|
git_dirty_not_cached = `git diff --shortstat 2>/dev/null`.length > 0
|
72
|
+
|
73
|
+
# are there staged changes?
|
61
74
|
git_dirty_cached = `git diff --shortstat --cached 2>/dev/null`.length > 0
|
62
75
|
|
63
76
|
if git_dirty_not_cached || git_dirty_cached
|
77
|
+
# uncommitted changes
|
64
78
|
git_branch = intense_cyan(git_current_branch)
|
65
79
|
else
|
80
|
+
# no uncommitted changes
|
66
81
|
git_branch = cyan(git_current_branch)
|
67
82
|
end
|
68
83
|
else
|
69
84
|
git_branch = ""
|
70
85
|
end
|
71
86
|
|
72
|
-
|
73
|
-
|
74
|
-
# ~/source/playground/yap master ➜
|
75
|
-
last_prompt = "#{dark(green('£'))} #{yellow(pwd)} #{git_branch}#{red(arrow)} "
|
87
|
+
# Example: ~/source/playground/yap master ➜
|
88
|
+
"#{yellow(pwd)} #{git_branch}#{red('➜')} "
|
76
89
|
end
|
77
90
|
|
78
|
-
|
91
|
+
###############################################################################
|
92
|
+
# SECONDARY PROMPT
|
93
|
+
#------------------------------------------------------------------------------
|
79
94
|
# The secondary_prompt is equivalent to the PS2 prompt in bash. It is what
|
80
95
|
# is displayed when entering a multiline command. It can be set to a string
|
81
96
|
# or a proc. It defaults to '> '
|
@@ -120,7 +135,7 @@ self.secondary_prompt = '> '
|
|
120
135
|
# Sets the default trigger key for all keyboard macros
|
121
136
|
world.addons[:keyboard_macros].trigger_key = ?\C-g
|
122
137
|
|
123
|
-
# Sets the default cancel key for all keyboard macros
|
138
|
+
# Sets the default cancel key (space) for all keyboard macros
|
124
139
|
world.addons[:keyboard_macros].cancel_key = " "
|
125
140
|
|
126
141
|
# Sets the default timeout for macros. When set to nil you will have to
|
@@ -144,12 +159,13 @@ end
|
|
144
159
|
# by specifying it when you call .configure(...).
|
145
160
|
world.addons[:keyboard_macros].configure(trigger_key: ?\C-g) do |macro|
|
146
161
|
macro.start do
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
162
|
+
# TODO: FUTURE
|
163
|
+
# world.editor.content_box.children = [
|
164
|
+
# TerminalLayout::Box.new(content: "am i floating1?", style: {display: :float, float: :right, height: 1, width: "am i floating1?".length}),
|
165
|
+
# TerminalLayout::Box.new(content: "What up12?", style: {display: :block}),
|
166
|
+
# TerminalLayout::Box.new(content: "Not much21", style: {display: :block}),
|
167
|
+
# TerminalLayout::Box.new(content: "am i floating3?", style: {display: :float, float: :left, height: 1, width: "am i floating1?".length}),
|
168
|
+
# ]
|
153
169
|
end
|
154
170
|
|
155
171
|
macro.stop do
|
@@ -183,6 +199,8 @@ world.addons[:keyboard_macros].configure(trigger_key: ?\C-g) do |macro|
|
|
183
199
|
end
|
184
200
|
end
|
185
201
|
|
202
|
+
# The below macro shows that you can have macros start with a different
|
203
|
+
# trigger keys.
|
186
204
|
# world.addons[:keyboard_macros].configure(trigger_key: :ctrl_h) do |macros|
|
187
205
|
# macros.define 'h123', -> {
|
188
206
|
# box = TerminalLayout::Box.new(content: "Right?", style: { display: :block, float: :right, height: 1, width: 50 })
|
data/yap-shell.gemspec
CHANGED
@@ -30,6 +30,10 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
|
31
31
|
| alias yap='env -i PATH=$PATH RUBYOPT="-rubygems -EUTF-8" HOME=$HOME sh -c "rbenv local 2.2.3 && yap"'
|
32
32
|
|
|
33
|
+
|If you are interested in tracing yap's execution you can add the DEBUG and TREEFELL_OUT options:
|
34
|
+
|
|
35
|
+
| alias yap-debug='env -i DEBUG=* TREEFELL_OUT=/tmp/yap-debug.log PATH=$PATH RUBYOPT="-rubygems -EUTF-8" HOME=$HOME sh -c "rbenv local 2.2.3 && yap"'
|
36
|
+
|
|
33
37
|
|Then, `source ~/.profile` or reload your shell. Now you can finally run:
|
34
38
|
|
|
35
39
|
| yap
|
@@ -65,7 +69,7 @@ Gem::Specification.new do |spec|
|
|
65
69
|
spec.add_dependency "term-ansicolor", "~> 1.3"
|
66
70
|
spec.add_dependency "ruby-termios", "~> 0.9.6"
|
67
71
|
spec.add_dependency "ruby-terminfo", "~> 0.1.1"
|
68
|
-
spec.add_dependency "yap-rawline", "~> 0.3.
|
72
|
+
spec.add_dependency "yap-rawline", "~> 0.3.2"
|
69
73
|
spec.add_dependency "treefell", "~> 0.2.3"
|
70
74
|
|
71
75
|
spec.add_development_dependency "bundler", "~> 1.6"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yap-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.3.
|
89
|
+
version: 0.3.2
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.3.
|
96
|
+
version: 0.3.2
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: treefell
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,7 +209,7 @@ files:
|
|
209
209
|
- lib/yap/shell/version.rb
|
210
210
|
- lib/yap/world.rb
|
211
211
|
- lib/yap/world/addons.rb
|
212
|
-
- rcfiles
|
212
|
+
- rcfiles/yaprc
|
213
213
|
- scripts/4
|
214
214
|
- scripts/bg-vim
|
215
215
|
- scripts/fail
|
@@ -232,6 +232,9 @@ post_install_message: "\nGreetings forward-thinking traveler!\n\nLet's waste no
|
|
232
232
|
it into this very release.\n\n\e[033mLastly\e[0m, create an alias to the yap executable
|
233
233
|
using the ruby version\nyou just installed it for. For example, with rbenv I use
|
234
234
|
the below\nalias in my ~/.profile file:\n\n alias yap='env -i PATH=$PATH RUBYOPT=\"-rubygems
|
235
|
+
-EUTF-8\" HOME=$HOME sh -c \"rbenv local 2.2.3 && yap\"'\n\nIf you are interested
|
236
|
+
in tracing yap's execution you can add the DEBUG and TREEFELL_OUT options:\n\n alias
|
237
|
+
yap-debug='env -i DEBUG=* TREEFELL_OUT=/tmp/yap-debug.log PATH=$PATH RUBYOPT=\"-rubygems
|
235
238
|
-EUTF-8\" HOME=$HOME sh -c \"rbenv local 2.2.3 && yap\"'\n\nThen, `source ~/.profile`
|
236
239
|
or reload your shell. Now you can finally run:\n\n yap\n\nYou know your tooling
|
237
240
|
better than me. If you need things to go a little\ndifferently than above you go
|