completely 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +32 -8
- data/lib/completely/cli.rb +1 -1
- data/lib/completely/command.rb +12 -4
- data/lib/completely/completions.rb +11 -0
- data/lib/completely/template.erb +1 -1
- data/lib/completely/version.rb +1 -1
- data/lib/completely.rb +0 -2
- metadata +1 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c09f951fc28b18f24c2c28fd7c80a15b3731aa07456145ab905c63c2b0dc9634
|
|
4
|
+
data.tar.gz: a9a25173ab3358e7eea42fe38552cbced8c6602bf5a0e9e6c414555420ae7af6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6edd13c5a0084485b7cb7114c45cf30d8c144075a3791aa51a8f5e7fc71df825cb03cb4786bc8fb3832f7bc1a46f06876614493184c4602d7e2e0dfbd3d4854
|
|
7
|
+
data.tar.gz: f8eb6cb08636c4281b50d7542d3c92fc8c6914e10597605f48e29ae342b6fb8cd31fff84de9e81dc0a7011bd5e963469c11fe025719e537238883d0a5812b5d9
|
data/README.md
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/completely)
|
|
4
4
|
[](https://github.com/DannyBen/completely/actions?query=workflow%3ATest)
|
|
5
|
+
[](https://codeclimate.com/github/DannyBen/completely/maintainability)
|
|
5
6
|
|
|
6
7
|
---
|
|
7
8
|
|
|
8
9
|
Completely is a command line utility and a Ruby library that lets you generate
|
|
9
10
|
bash completion scripts from simple YAML configuration.
|
|
10
11
|
|
|
11
|
-
This tool is for you
|
|
12
|
+
This tool is for you if:
|
|
12
13
|
|
|
13
14
|
1. You develop your own command line tools.
|
|
14
15
|
2. Your life feels empty without bash completions.
|
|
@@ -19,11 +20,11 @@ This tool is for you it:
|
|
|
19
20
|
|
|
20
21
|
## Install
|
|
21
22
|
|
|
22
|
-
```
|
|
23
|
+
```bash
|
|
23
24
|
$ gem install completely
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
##
|
|
27
|
+
## Using the `completely` command line
|
|
27
28
|
|
|
28
29
|
The `completely` command line works with a simple YAML configuration file as
|
|
29
30
|
input, and generates a bash completions script as output.
|
|
@@ -78,7 +79,7 @@ follows it will be suggested as completions.
|
|
|
78
79
|
|
|
79
80
|
To generate the bash script, simply run:
|
|
80
81
|
|
|
81
|
-
```
|
|
82
|
+
```bash
|
|
82
83
|
$ completely generate
|
|
83
84
|
|
|
84
85
|
# or, to just preview it without saving:
|
|
@@ -87,7 +88,7 @@ $ completely preview
|
|
|
87
88
|
|
|
88
89
|
For more options (like setting input/output path), run
|
|
89
90
|
|
|
90
|
-
```
|
|
91
|
+
```bash
|
|
91
92
|
$ completely --help
|
|
92
93
|
```
|
|
93
94
|
|
|
@@ -99,7 +100,7 @@ You may have noticed that the sample file contains two special entries:
|
|
|
99
100
|
- `<directory>`
|
|
100
101
|
|
|
101
102
|
These patterns will add the list of files and directories
|
|
102
|
-
(when `<file>` is used) or just directories (when `<directory
|
|
103
|
+
(when `<file>` is used) or just directories (when `<directory>` is used) to
|
|
103
104
|
the list of suggestions.
|
|
104
105
|
|
|
105
106
|
For those interested in the technical details, any word between `<...>` will
|
|
@@ -107,17 +108,40 @@ simply be added using the [`compgen -A action`][compgen] function, so you can
|
|
|
107
108
|
in fact use any of its supported arguments.
|
|
108
109
|
|
|
109
110
|
|
|
110
|
-
|
|
111
|
+
## Using the generated completion scripts
|
|
111
112
|
|
|
112
113
|
In order to enable the completions, simply source the generated script:
|
|
113
114
|
|
|
114
|
-
```
|
|
115
|
+
```bash
|
|
115
116
|
$ source completely.bash
|
|
116
117
|
```
|
|
117
118
|
|
|
118
119
|
You may wish to add this to your `~/.bashrc` file to enable this for future
|
|
119
120
|
sessions (just be sure to use absolute path).
|
|
120
121
|
|
|
122
|
+
## Using from within Ruby code
|
|
123
|
+
|
|
124
|
+
```ruby
|
|
125
|
+
require 'completely'
|
|
126
|
+
|
|
127
|
+
# Load from file
|
|
128
|
+
completions = Completely::Completions.load "input.yaml"
|
|
129
|
+
|
|
130
|
+
# Or, from a hash
|
|
131
|
+
input = {
|
|
132
|
+
"mygit" => %w[--help --version status init commit],
|
|
133
|
+
"mygit status" => %w[--help --verbose --branch]
|
|
134
|
+
}
|
|
135
|
+
completions = Completely::Completions.new input
|
|
136
|
+
|
|
137
|
+
# Generate the script
|
|
138
|
+
puts completions.script
|
|
139
|
+
|
|
140
|
+
# Or, generate a function that echos the script
|
|
141
|
+
puts completions.wrapper_function
|
|
142
|
+
puts completions.wrapper_function "custom_function_name"
|
|
143
|
+
```
|
|
144
|
+
|
|
121
145
|
|
|
122
146
|
## Contributing / Support
|
|
123
147
|
|
data/lib/completely/cli.rb
CHANGED
data/lib/completely/command.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Completely
|
|
|
5
5
|
|
|
6
6
|
usage "completely new [CONFIG_PATH]"
|
|
7
7
|
usage "completely preview [CONFIG_PATH --function NAME]"
|
|
8
|
-
usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME]"
|
|
8
|
+
usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]"
|
|
9
9
|
usage "completely (-h|--help|--version)"
|
|
10
10
|
|
|
11
11
|
command "new", "Create a new sample YAML configuration file"
|
|
@@ -13,16 +13,18 @@ module Completely
|
|
|
13
13
|
command "generate", "Generate the bash completion script to a file"
|
|
14
14
|
|
|
15
15
|
option "-f --function NAME", "Modify the name of the function in the generated script"
|
|
16
|
+
option "-w --wrap NAME", "Wrap the completion script inside a function that echos the script. This is useful if you wish to embed it directly in your script"
|
|
16
17
|
|
|
17
18
|
param "CONFIG_PATH", "Path to the YAML configuration file"
|
|
18
19
|
param "OUTPUT_PATH", "Path to the output bash script"
|
|
19
20
|
|
|
20
21
|
example "completely new"
|
|
21
22
|
example "completely new input.yaml"
|
|
22
|
-
example "completely preview --function
|
|
23
|
+
example "completely preview --function _my_completions"
|
|
23
24
|
example "completely generate"
|
|
24
25
|
example "completely generate input.yaml"
|
|
25
|
-
example "completely generate input.yaml output.sh -f
|
|
26
|
+
example "completely generate input.yaml output.sh -f _my_completions"
|
|
27
|
+
example "completely generate -w give_comps -f my_completions"
|
|
26
28
|
|
|
27
29
|
def new_command
|
|
28
30
|
if File.exist? config_path
|
|
@@ -38,7 +40,9 @@ module Completely
|
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
def generate_command
|
|
41
|
-
|
|
43
|
+
wrap = args['--wrap']
|
|
44
|
+
output = wrap ? wrapper_function(wrap) : script
|
|
45
|
+
File.write output_path, output
|
|
42
46
|
say "Saved !txtpur!#{output_path}"
|
|
43
47
|
end
|
|
44
48
|
|
|
@@ -64,6 +68,10 @@ module Completely
|
|
|
64
68
|
@script ||= completions.script
|
|
65
69
|
end
|
|
66
70
|
|
|
71
|
+
def wrapper_function(wrapper_name)
|
|
72
|
+
completions.wrapper_function wrapper_name
|
|
73
|
+
end
|
|
74
|
+
|
|
67
75
|
def completions
|
|
68
76
|
@completions ||= Completions.load(config_path, function_name: args['--function'])
|
|
69
77
|
end
|
|
@@ -19,6 +19,17 @@ module Completely
|
|
|
19
19
|
ERB.new(template, trim_mode: '%-').result(binding)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
def wrapper_function(name = nil)
|
|
23
|
+
name ||= "send_completions"
|
|
24
|
+
|
|
25
|
+
script_lines = script.split("\n").map do |line|
|
|
26
|
+
clean_line = line.gsub("'") { "\\'" }
|
|
27
|
+
%Q[ echo $'#{clean_line}']
|
|
28
|
+
end.join("\n")
|
|
29
|
+
|
|
30
|
+
"#{name}() {\n#{script_lines}\n}"
|
|
31
|
+
end
|
|
32
|
+
|
|
22
33
|
private
|
|
23
34
|
|
|
24
35
|
def template_path
|
data/lib/completely/template.erb
CHANGED
data/lib/completely/version.rb
CHANGED
data/lib/completely.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: completely
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Danny Ben Shitrit
|
|
@@ -38,20 +38,6 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0.7'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: requires
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0.1'
|
|
48
|
-
type: :runtime
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0.1'
|
|
55
41
|
description: Generate bash completion scripts using simple YAML configuration
|
|
56
42
|
email: db@dannyben.com
|
|
57
43
|
executables:
|