mysh 0.6.3 → 0.6.4
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/README.md +23 -6
- data/lib/mysh.rb +1 -0
- data/lib/mysh/exceptions.rb +8 -2
- data/lib/mysh/globalize.rb +16 -0
- data/lib/mysh/internal/actions/cd.rb +7 -1
- data/lib/mysh/internal/actions/elapsed.rb +1 -1
- data/lib/mysh/internal/actions/help.rb +13 -2
- data/lib/mysh/internal/actions/help/gls.txt +3 -3
- data/lib/mysh/internal/actions/help/h_o_h.txt +8 -0
- data/lib/mysh/internal/format.rb +1 -9
- data/lib/mysh/internal/format/array.rb +4 -4
- data/lib/mysh/output_pager.rb +101 -0
- data/lib/mysh/process.rb +6 -4
- data/lib/mysh/shell_variables.rb +5 -0
- data/lib/mysh/sources/smart_auto_complete.rb +7 -1
- data/lib/mysh/user_input.rb +1 -1
- data/lib/mysh/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcab3e7234b02634d2b6d35c021a6e74d1e500e9
|
4
|
+
data.tar.gz: 9bc8b2270e6a4616d5c9f01802383992be7d010d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79c6c862dd727aa571b5d465a0cd61509615b08ee016bb6b9b981f7aa1f305fc9627014ff80a63332ed2e933a300e875cd1efff4b02dd37c1ac7731f6aa76957
|
7
|
+
data.tar.gz: c6cfd30e004d5e2e12120c3aa0876cc485b6b8aae49d64fc432e968daf3d93b1d73d5f2c85fbae4d58e37544bb6c25d6e948d067720906fe2375598c9011f859
|
data/README.md
CHANGED
@@ -203,16 +203,18 @@ Normally an input is one line entered by the user. Like this:
|
|
203
203
|
```
|
204
204
|
mysh> ls *.rb
|
205
205
|
```
|
206
|
-
In mysh, the user is able
|
207
|
-
|
206
|
+
In mysh, the user is able enter Ruby code directly at the command line. Since
|
207
|
+
these commands can be rather long, there is a need to to chain together
|
208
|
+
multiple lines and have them treated as a single input. So for the following
|
209
|
+
scenario:
|
208
210
|
```
|
209
|
-
mysh
|
210
|
-
mysh\line two
|
211
|
-
mysh\line three
|
211
|
+
mysh>= "line one" +\
|
212
|
+
mysh\"line two" +\
|
213
|
+
mysh\"line three"
|
212
214
|
```
|
213
215
|
The input string will be:
|
214
216
|
```
|
215
|
-
"line one
|
217
|
+
"="line one" +\n"line two" +\n"line three"\n"
|
216
218
|
```
|
217
219
|
Note that while the prompt is user configurable, it will always end with '>'
|
218
220
|
for the initial line and '\\' for subsequent lines.
|
@@ -582,6 +584,8 @@ types | Help on mysh file types.
|
|
582
584
|
usage | Help on mysh usage options.
|
583
585
|
{{ | Help on mysh handlebars.
|
584
586
|
|
587
|
+
Also, absent any detailed help information, the help command will show the
|
588
|
+
summary of any internal command.
|
585
589
|
|
586
590
|
### Shell Info
|
587
591
|
|
@@ -889,6 +893,19 @@ information.
|
|
889
893
|
To add a new help topic, simply add the new help file to the help folder and
|
890
894
|
and a corresponding line entry to to the help variable.
|
891
895
|
|
896
|
+
#### Exceptions:
|
897
|
+
|
898
|
+
As an application, exception handling is largely an internal matter. However,
|
899
|
+
since user code can be embedded in mysh, they should be documented. The mysh
|
900
|
+
application gem uses the following exception classes:
|
901
|
+
|
902
|
+
Exception # From Ruby.
|
903
|
+
StandardError # From Ruby.
|
904
|
+
MyshException # The abstract base exception for mysh.
|
905
|
+
MyshExit # Exit the current mysh processing loop.
|
906
|
+
MyshStopOutput # Stop further output from a verbose command.
|
907
|
+
|
908
|
+
|
892
909
|
## Contributing
|
893
910
|
|
894
911
|
All participation is welcomed. There are two fabulous plans to choose from:
|
data/lib/mysh.rb
CHANGED
@@ -8,6 +8,7 @@ require 'in_array'
|
|
8
8
|
require_relative 'mysh/exceptions'
|
9
9
|
require_relative 'mysh/binding_wrapper'
|
10
10
|
require_relative 'mysh/input_wrapper'
|
11
|
+
require_relative 'mysh/output_pager'
|
11
12
|
require_relative 'mysh/user_input'
|
12
13
|
require_relative 'mysh/expression'
|
13
14
|
require_relative 'mysh/internal'
|
data/lib/mysh/exceptions.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
#
|
4
|
-
class
|
3
|
+
# The abstract base exception of the mysh.
|
4
|
+
class MyshException < StandardError; end
|
5
|
+
|
6
|
+
# Exit the current mysh processing loop.
|
7
|
+
class MyshExit < MyshException; end
|
8
|
+
|
9
|
+
# Stop further output from a verbose command.
|
10
|
+
class MyshStopOutput < MyshException; end
|
data/lib/mysh/globalize.rb
CHANGED
@@ -15,4 +15,20 @@ class Object
|
|
15
15
|
Mysh.try_execute_command(str)
|
16
16
|
end
|
17
17
|
|
18
|
+
# Execute a block with page paused output.
|
19
|
+
def more
|
20
|
+
saved = $stdout
|
21
|
+
|
22
|
+
if MNV[:page_pause].extract_mysh_types
|
23
|
+
$stdout = OutputPager.new if (outer = $stdout.equal?($mysh_out))
|
24
|
+
end
|
25
|
+
|
26
|
+
yield
|
27
|
+
rescue MyshStopOutput
|
28
|
+
raise unless outer
|
29
|
+
return
|
30
|
+
ensure
|
31
|
+
$stdout = saved
|
32
|
+
end
|
33
|
+
|
18
34
|
end
|
@@ -11,7 +11,13 @@ module Mysh
|
|
11
11
|
if (args = input.args).empty?
|
12
12
|
puts Dir.pwd.to_host_spec
|
13
13
|
else
|
14
|
-
|
14
|
+
begin
|
15
|
+
Dir.chdir(args[0])
|
16
|
+
rescue Errno::ENOENT
|
17
|
+
puts "Cannot find \"#{args[0]}\""
|
18
|
+
rescue Errno::EINVAL
|
19
|
+
puts "The file \"#{args[0]}\" is not a directory."
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
@@ -5,7 +5,18 @@ module Mysh
|
|
5
5
|
|
6
6
|
# Help action pool of topics.
|
7
7
|
default = Action.new do |args|
|
8
|
-
|
8
|
+
topic = args[0]
|
9
|
+
help = []
|
10
|
+
|
11
|
+
COMMANDS.actions_info.each do |cmd|
|
12
|
+
help << cmd if cmd[0].start_with?(topic)
|
13
|
+
end
|
14
|
+
|
15
|
+
if help.empty?
|
16
|
+
puts "No help found for #{topic.inspect}."
|
17
|
+
else
|
18
|
+
puts help.format_mysh_bullets
|
19
|
+
end
|
9
20
|
end
|
10
21
|
|
11
22
|
HELP = ActionPool.new("HELP", default)
|
@@ -24,7 +35,7 @@ module Mysh
|
|
24
35
|
end
|
25
36
|
|
26
37
|
# The base help command.
|
27
|
-
desc = 'Display help information for mysh with an optional topic.'
|
38
|
+
desc = 'Display help information for mysh with an optional topic. See ?? for more.'
|
28
39
|
COMMANDS.add_action(HelpCommand.new('help <topic>', desc))
|
29
40
|
#The help command action object.
|
30
41
|
HELP_COMMAND = HelpCommand.new('?<topic>', desc)
|
@@ -25,15 +25,15 @@ crass mini_portile2 rack-test thread_safe
|
|
25
25
|
|
26
26
|
mysh>gls -l vls
|
27
27
|
name vls
|
28
|
-
version 0.4.
|
29
|
-
date 2016-10-
|
28
|
+
version 0.4.1
|
29
|
+
date 2016-10-27 00:00:00 UTC
|
30
30
|
summary A version listing utility.
|
31
31
|
description A CLI and Rails console utility that lists the versions of modules
|
32
32
|
used by the specified gems/ruby files or Rails project.
|
33
33
|
executables vls
|
34
34
|
authors Peter Camilleri
|
35
35
|
email peter.c.camilleri@gmail.com
|
36
|
-
homepage
|
36
|
+
homepage https://github.com/PeterCamilleri/vls
|
37
37
|
|
38
38
|
A complete guide to the gem specification's properties may be found at:
|
39
39
|
http://guides.rubygems.org/specification-reference/
|
@@ -10,3 +10,11 @@ The available help topics are:
|
|
10
10
|
|
11
11
|
{{ HELP.actions_info.format_mysh_bullets }}
|
12
12
|
|
13
|
+
Brief summaries are also available on the following internal commands:
|
14
|
+
|
15
|
+
{{ Mysh::COMMANDS.actions_info
|
16
|
+
.reject{|cmd| cmd[1]["See ?"]}
|
17
|
+
.map{|cmd| cmd[0].split[0] }
|
18
|
+
.join(" ")
|
19
|
+
}}
|
20
|
+
|
data/lib/mysh/internal/format.rb
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
module Mysh
|
5
|
-
|
6
|
-
#Assume an 80 column working area for formatting.
|
7
|
-
PAGE_WIDTH = 80
|
8
|
-
|
9
|
-
end
|
10
|
-
|
3
|
+
# Grab the mysh formatters
|
11
4
|
require_relative 'format/bullets'
|
12
5
|
require_relative 'format/columns'
|
13
6
|
require_relative 'format/array'
|
14
7
|
require_relative 'format/string'
|
15
8
|
require_relative 'format/object'
|
16
9
|
require_relative 'format/nil'
|
17
|
-
|
@@ -6,7 +6,7 @@ class Array
|
|
6
6
|
# Columns ========================================================
|
7
7
|
|
8
8
|
#Print out the array with efficient columns.
|
9
|
-
def puts_mysh_columns(page_width =
|
9
|
+
def puts_mysh_columns(page_width = MiniTerm.width)
|
10
10
|
puts format_mysh_columns(page_width)
|
11
11
|
end
|
12
12
|
|
@@ -30,7 +30,7 @@ class Array
|
|
30
30
|
#* A string.
|
31
31
|
#<br>Endemic Code Smells
|
32
32
|
#* :reek:FeatureEnvy -- false positive.
|
33
|
-
def format_mysh_columns(page_width =
|
33
|
+
def format_mysh_columns(page_width = MiniTerm.width)
|
34
34
|
raw_mysh_columns(page_width).join("\n")
|
35
35
|
end
|
36
36
|
|
@@ -45,7 +45,7 @@ class Array
|
|
45
45
|
# Bullets ========================================================
|
46
46
|
|
47
47
|
#Print out the array as bullet points.
|
48
|
-
def puts_mysh_bullets(page_width =
|
48
|
+
def puts_mysh_bullets(page_width = MiniTerm.width)
|
49
49
|
puts format_mysh_bullets(page_width)
|
50
50
|
end
|
51
51
|
|
@@ -54,7 +54,7 @@ class Array
|
|
54
54
|
#* A string.
|
55
55
|
#<br>Endemic Code Smells
|
56
56
|
#* :reek:FeatureEnvy -- false positive.
|
57
|
-
def format_mysh_bullets(page_width =
|
57
|
+
def format_mysh_bullets(page_width = MiniTerm.width)
|
58
58
|
return "" if empty?
|
59
59
|
|
60
60
|
builder = Mysh::BulletPoints.new(page_width)
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$mysh_out = $stdout # Keep a copy of the real $stdout.
|
4
|
+
|
5
|
+
# A class to manage paged output.
|
6
|
+
class OutputPager
|
7
|
+
|
8
|
+
# Set up the initial values.
|
9
|
+
def initialize
|
10
|
+
@lines = 0
|
11
|
+
@chars = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
# Write out a general string with page pauses.
|
15
|
+
def write(str)
|
16
|
+
while !str.empty?
|
17
|
+
pre,mid,str = str.partition("\n")
|
18
|
+
write_str(pre) unless pre.empty?
|
19
|
+
writeln unless mid.empty?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Write out a simple string with no embedded new-lines.
|
26
|
+
def write_str(str)
|
27
|
+
loop do
|
28
|
+
len = str.length
|
29
|
+
|
30
|
+
if @chars + len < chars_per_line
|
31
|
+
$mysh_out.write(str)
|
32
|
+
@chars += len
|
33
|
+
return
|
34
|
+
else
|
35
|
+
tilt = chars_per_line - @chars
|
36
|
+
$mysh_out.write(str[0, tilt])
|
37
|
+
count_lines
|
38
|
+
|
39
|
+
str = (str[tilt..-1])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Write out a new-line.
|
45
|
+
def writeln
|
46
|
+
$mysh_out.write("\n")
|
47
|
+
count_lines
|
48
|
+
end
|
49
|
+
|
50
|
+
# A new line is out, count it!
|
51
|
+
def count_lines
|
52
|
+
@chars = 0
|
53
|
+
@lines += 1
|
54
|
+
|
55
|
+
if @lines >= (lines_per_page - 1)
|
56
|
+
case pause.downcase
|
57
|
+
when " "
|
58
|
+
@lines -= 1
|
59
|
+
when "q"
|
60
|
+
raise MyshStopOutput
|
61
|
+
else
|
62
|
+
@lines = 0
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Pause waiting for the user.
|
68
|
+
def pause
|
69
|
+
msg = pause_message
|
70
|
+
$mysh_out.write(msg)
|
71
|
+
|
72
|
+
MiniTerm.raw do |term|
|
73
|
+
result = term.get_raw_char
|
74
|
+
term.flush
|
75
|
+
result
|
76
|
+
end
|
77
|
+
|
78
|
+
ensure
|
79
|
+
$mysh_out.write("\r" + " " * msg.length + "\r")
|
80
|
+
end
|
81
|
+
|
82
|
+
# How many lines fit on a page?
|
83
|
+
def lines_per_page
|
84
|
+
result = MNV[:page_height].to_i
|
85
|
+
result = MiniTerm.height if result < 2
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
89
|
+
# How many characters fit on a line?
|
90
|
+
def chars_per_line
|
91
|
+
result = MNV[:page_width].to_i
|
92
|
+
result = MiniTerm.width if result < 20
|
93
|
+
result
|
94
|
+
end
|
95
|
+
|
96
|
+
# Get the text of the pause message.
|
97
|
+
def pause_message
|
98
|
+
MNV.key?(:page_msg) ? MNV[:page_msg] : "Press enter, space or q:"
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
data/lib/mysh/process.rb
CHANGED
@@ -39,10 +39,12 @@ module Mysh
|
|
39
39
|
def self.try_execute_command(str)
|
40
40
|
input = InputWrapper.new(str)
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
more do
|
43
|
+
try_execute_quick(input) ||
|
44
|
+
try_execute_internal(input) ||
|
45
|
+
try_execute_external(input) ||
|
46
|
+
try_execute_system(input)
|
47
|
+
end
|
46
48
|
end
|
47
49
|
|
48
50
|
end
|
data/lib/mysh/shell_variables.rb
CHANGED
@@ -16,6 +16,11 @@ module Mysh
|
|
16
16
|
MNV[:post_prompt] = "$prompt"
|
17
17
|
MNV[:pre_prompt] = "$w"
|
18
18
|
|
19
|
+
MNV[:page_width] = "{{ MiniTerm.width }}"
|
20
|
+
MNV[:page_height] = "{{ MiniTerm.height }}"
|
21
|
+
MNV[:page_pause] = "on"
|
22
|
+
MNV[:page_msg] = "Press a key, a space, or q:"
|
23
|
+
|
19
24
|
MNV[:d] = "{{ Time.now.strftime(MNV[:date_fmt]) }}"
|
20
25
|
MNV[:h] = "{{ ENV['HOME'].to_host_spec }}"
|
21
26
|
MNV[:r] = "{{ RbConfig.ruby.to_host_spec }}"
|
@@ -16,13 +16,19 @@ module Mysh
|
|
16
16
|
|
17
17
|
#Construct a new data list for auto-complete
|
18
18
|
def rebuild(str)
|
19
|
+
if /(?<=\s|^)\$[a-z][a-z0-9_]*\z/ =~ str
|
20
|
+
sym = $MATCH[1..-1].to_sym
|
21
|
+
@active_source = nil
|
22
|
+
return @str = $PREMATCH + MNV[sym] if MNV.key?(sym)
|
23
|
+
end
|
24
|
+
|
19
25
|
@active_source = (@prefix || str[0]) == '=' ? @quote_source : @auto_source
|
20
26
|
@active_source.rebuild(str)
|
21
27
|
end
|
22
28
|
|
23
29
|
#Get the next string for auto-complete
|
24
30
|
def next
|
25
|
-
@active_source.next
|
31
|
+
@active_source ? @active_source.next : @str
|
26
32
|
end
|
27
33
|
|
28
34
|
end
|
data/lib/mysh/user_input.rb
CHANGED
data/lib/mysh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -220,6 +220,7 @@ files:
|
|
220
220
|
- lib/mysh/internal/format/string.rb
|
221
221
|
- lib/mysh/internal/manage.rb
|
222
222
|
- lib/mysh/internal/to_file_spec.rb
|
223
|
+
- lib/mysh/output_pager.rb
|
223
224
|
- lib/mysh/pre_processor.rb
|
224
225
|
- lib/mysh/process.rb
|
225
226
|
- lib/mysh/quick.rb
|