lightning 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +9 -0
- data/README.rdoc +53 -125
- data/Rakefile +14 -40
- data/bin/lightning +4 -0
- data/bin/lightning-complete +1 -10
- data/bin/lightning-translate +4 -0
- data/lib/lightning.rb +36 -50
- data/lib/lightning/bolt.rb +53 -26
- data/lib/lightning/builder.rb +87 -0
- data/lib/lightning/commands.rb +92 -69
- data/lib/lightning/commands/bolt.rb +63 -0
- data/lib/lightning/commands/core.rb +57 -0
- data/lib/lightning/commands/function.rb +76 -0
- data/lib/lightning/commands/shell_command.rb +38 -0
- data/lib/lightning/commands_util.rb +75 -0
- data/lib/lightning/completion.rb +72 -28
- data/lib/lightning/completion_map.rb +42 -39
- data/lib/lightning/config.rb +92 -57
- data/lib/lightning/function.rb +70 -0
- data/lib/lightning/generator.rb +77 -43
- data/lib/lightning/generators.rb +53 -0
- data/lib/lightning/generators/misc.rb +12 -0
- data/lib/lightning/generators/ruby.rb +32 -0
- data/lib/lightning/util.rb +70 -0
- data/lib/lightning/version.rb +3 -0
- data/test/bolt_test.rb +16 -28
- data/test/builder_test.rb +54 -0
- data/test/commands_test.rb +98 -0
- data/test/completion_map_test.rb +31 -54
- data/test/completion_test.rb +106 -36
- data/test/config_test.rb +22 -56
- data/test/function_test.rb +90 -0
- data/test/generator_test.rb +73 -0
- data/test/lightning.yml +26 -34
- data/test/test_helper.rb +80 -15
- metadata +42 -20
- data/VERSION.yml +0 -4
- data/bin/lightning-full_path +0 -18
- data/bin/lightning-install +0 -7
- data/lib/lightning/bolts.rb +0 -12
- data/lightning.yml.example +0 -87
- data/lightning_completions.example +0 -147
- data/test/lightning_test.rb +0 -58
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 0.3.0
|
2
|
+
* Major refactoring
|
3
|
+
* Added pluggable commands and generators
|
4
|
+
* Added several commands to completely configure lightning from commandline
|
5
|
+
* Improved autocompletion including white space escaping and remote completion
|
6
|
+
* Added support for zsh
|
7
|
+
* Added more thorough error handling
|
8
|
+
* Switched to yardoc and bacon for docs + tests
|
9
|
+
|
1
10
|
== 0.2.1
|
2
11
|
* Rubyforge release
|
3
12
|
* Removed monkey patches
|
data/README.rdoc
CHANGED
@@ -1,150 +1,78 @@
|
|
1
1
|
== Description
|
2
|
+
Lightning is a commandline framework that could revolutionize how fast you are on the commandline. Lightning let’s you easily define and generate shell functions which autocomplete and interpret paths (files and directories) by their basenames. With these functions you don’t have to ever type the full path to any file for any command again.
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
and you're ready to rock.
|
4
|
+
== Intro
|
5
|
+
Lightning generates shell functions which can interpret paths by their basenames. So instead of carpal-typing
|
6
6
|
|
7
|
-
|
7
|
+
$ less /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb
|
8
8
|
|
9
|
-
|
9
|
+
just type
|
10
10
|
|
11
|
-
|
11
|
+
$ less-ruby irb.rb
|
12
12
|
|
13
|
-
|
13
|
+
less-ruby is a lightning function which wraps `less` with the ability to refer to system ruby files by their basenames. Being a lightning function, it can also autocomplete system ruby files:
|
14
14
|
|
15
|
-
|
15
|
+
# 1112 available system ruby files
|
16
|
+
$ less-ruby [TAB]
|
17
|
+
Display all 1112 possibilities? (y or n)
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
$ less-ruby a[TAB]
|
20
|
+
abbrev.rb abstract.rb abstract_index_builder.rb
|
21
|
+
$ less-ruby abb[TAB]
|
22
|
+
$ less-ruby abbrev.rb
|
23
|
+
# Pages /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/abbrev.rb ...
|
19
24
|
|
20
|
-
|
25
|
+
# Autocompletion works regardless of the number of arguments
|
26
|
+
$ less-ruby -I abbrev.rb y[TAB]
|
27
|
+
yaml.rb yamlnode.rb ypath.rb
|
28
|
+
$ less-ruby -I abbrev.rb yp[TAB]
|
29
|
+
$ less-ruby -I abbrev.rb ypath.rb
|
30
|
+
# Pages /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/abbrev.rb and
|
31
|
+
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml/ypath.rb ...
|
21
32
|
|
22
|
-
|
23
|
-
bash> rvim *dialog [TAB TAB]
|
24
|
-
canvasprintdialog.rb
|
25
|
-
extfileselectiondialog.rb
|
26
|
-
dialog.rb//System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/tk
|
27
|
-
fileselectiondialog.rb
|
28
|
-
dialog.rb//System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/tkextlib/bwidget
|
29
|
-
finddialog.rb
|
30
|
-
|
31
|
-
#re-edit your line to narrow down your completion to one entry
|
32
|
-
bash> rvim ca*dialog [TAB TAB]
|
33
|
-
|
34
|
-
#once the basename completes, you can execute your command
|
35
|
-
bash> rvim canvasprintdialog.rb
|
36
|
-
|
37
|
-
As you can see, you only need to autocomplete the basenames of paths and lightning will resolve their
|
38
|
-
full paths. In these examples, rvim is a lightning command configured to autocomplete a certain group of paths for vim.
|
39
|
-
In my case, rvim is configured to complete my ruby core and standard library files.
|
33
|
+
And here's the one-liner that creates this function:
|
40
34
|
|
35
|
+
$ lightning function create less ruby && lightning-reload
|
41
36
|
|
42
37
|
== Install
|
43
38
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
Use the Configuration section below and the provided lightning.yml.example as guides.
|
50
|
-
|
51
|
-
2. Execute `lightning-install` to generate ~/.lightning_completions from your config.
|
52
|
-
There is a config option for changing the location of the generated file. See Configuration
|
53
|
-
below. See lightning_completions.example for what would be generated for the enclosed example
|
54
|
-
config.
|
55
|
-
|
56
|
-
3. Source the generated file in your bashrc ie `source ~/.lightning_completions`.
|
57
|
-
|
58
|
-
|
59
|
-
== Globbable Paths
|
60
|
-
|
61
|
-
Since the globbable paths are interpreted by ruby's Dir.glob(), you can:
|
62
|
-
|
63
|
-
1. Autocomplete files and directories that don't start with specific letters.
|
64
|
-
|
65
|
-
Dir.glob("[^ls]*") -> Matches anything not starting with l or s
|
66
|
-
|
67
|
-
2. Autocomplete files ending with specific file extensions for a given directory.
|
39
|
+
Install with either rip or rubygems:
|
40
|
+
$ rip install git://github.com/cldwalker/lightning.git
|
41
|
+
# OR
|
42
|
+
$ sudo gem install yard # if you want lightning's documentation generated correctly
|
43
|
+
$ sudo gem install lightning
|
68
44
|
|
69
|
-
|
45
|
+
If you've installed with rubygems and `time lightning` takes longer than 0.05 seconds, I *strongly recommend* installing with rip. Your startup time directly effects your autocompletion speed with lightning.
|
70
46
|
|
71
|
-
|
47
|
+
Once lightning is installed, we need to do a one-time setup:
|
72
48
|
|
73
|
-
|
49
|
+
# To see available install options
|
50
|
+
$ lightning install -h
|
74
51
|
|
75
|
-
|
52
|
+
# Installs lightning's core files and sources the needed lightning functions
|
53
|
+
$ lightning install && source ~/.lightning/functions.sh
|
54
|
+
Created ~/.lightning_yml
|
55
|
+
Created ~/.lightning/functions.sh
|
76
56
|
|
77
|
-
|
57
|
+
# To have lightning's functionality loaded when your shell starts up
|
58
|
+
echo source ~/.lightning/functions.sh >> ~/.bashrc
|
59
|
+
# or for zsh
|
60
|
+
echo source ~/.lightning/functions.sh >> ~/.zshrc
|
78
61
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
== Configuration
|
83
|
-
|
84
|
-
It helps to look at lightning.yml.example while reading this.
|
85
|
-
|
86
|
-
Configuration options are:
|
87
|
-
|
88
|
-
* generated_file: Location of shell script file generated from config. Defaults to
|
89
|
-
~/.lightning_completions.
|
90
|
-
* ignore_paths: List of paths to globally ignore when listing completions.
|
91
|
-
* complete_regex: true or false (default is true)
|
92
|
-
Turns on/off Ruby regular expression matching when completing. One convience
|
93
|
-
is that a '*' is converted to '.*' ie glob-like behavior.
|
94
|
-
|
95
|
-
Note: Realize your regular expression normally just match the basename. However, since duplicates
|
96
|
-
list their full paths, their full paths are subject to regex matching.
|
97
|
-
* shell: Specifies shell script generator used for generating completions. Defaults to bash.
|
98
|
-
* aliases: A hash (pairs) of custom aliases pointing to full paths. These aliases will be globally
|
99
|
-
recognized by any lightning command.
|
100
|
-
* commands: A list of lightning commands. A lightning command is just a shell function
|
101
|
-
which executes a specified shell function with a defined set of paths to autocomplete on.
|
102
|
-
A command consists of the following options/keys:
|
103
|
-
|
104
|
-
* name (required): Name of the lightning command you'll be typing.
|
105
|
-
* map_to (required): Shell command which the lightning command passes arguments to.
|
106
|
-
* description: Description which is placed as a comment in the generated shell script.
|
107
|
-
* paths (required): A list of globbable paths, whose basenames are autocompleted. You can also
|
108
|
-
pass this a path name that has been defined in the paths option.
|
109
|
-
* aliases: A hash (pairs) of custom aliases and full paths only for this command.
|
110
|
-
|
111
|
-
* paths: This takes a hash (pairs) of path names and globbable paths. This should be used when
|
112
|
-
you have a group of paths that are used in multiple commands. When doing that, you would specify
|
113
|
-
the path name defined here in the command's paths key.
|
114
|
-
Note: path names should only be alphanumeric
|
115
|
-
|
116
|
-
* post_path: Text to add immediately after a resolved path. lightning.yml.example contains
|
117
|
-
an example used for opening gem documentation in your browser.
|
118
|
-
|
119
|
-
== Duplicate Basenames
|
120
|
-
|
121
|
-
So what happens when their are multiple matches for the same basename?
|
122
|
-
Lightning appends a '/' + the full directory to each of the basenames.
|
123
|
-
|
124
|
-
For example, if I autocomplete button.rb for my ruby standard libraries I get:
|
125
|
-
|
126
|
-
bash> rvim button.rb
|
127
|
-
button.rb//System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/tk
|
128
|
-
button.rb//System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/tkextlib/bwidget
|
129
|
-
button.rb//System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/tkextlib/blt/tile
|
130
|
-
|
131
|
-
This isn't the prettiest completion but it resolves duplicates, displays the path differences
|
132
|
-
between each and easily autocompletes. I'm open to suggestions on this syntax.
|
62
|
+
== Bugs/Issues
|
63
|
+
Please report them {on github}[http://github.com/cldwalker/lightning/issues].
|
133
64
|
|
134
65
|
== Limitations
|
135
|
-
*
|
136
|
-
*
|
137
|
-
it's not yet possible to resolve some arguments and not others.
|
138
|
-
|
139
|
-
== Motivation
|
66
|
+
* Completions that are a directory above or below a basename don't work for zsh.
|
67
|
+
* Only bash and zsh shells are supported. Patches are welcome to support other shells.
|
140
68
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
http://github.com/ryanb/dotfiles/blob/master/bash/completion_scripts/project_completion,
|
145
|
-
I had to do something.
|
69
|
+
== Credits
|
70
|
+
* ryanb's dotfiles inspired tinkering with autocompletion in ruby: http://github.com/ryanb/dotfiles/blob/master/bash/completion_scripts/project_completion
|
71
|
+
* defunkt's rip, http://github.com/defunkt/rip, was inflential in designing plugins
|
146
72
|
|
147
73
|
== Todo
|
148
|
-
*
|
149
|
-
*
|
150
|
-
*
|
74
|
+
* More tests
|
75
|
+
* Manpage
|
76
|
+
* Consider underscore anchored autocompletion i.e. textmate style file search
|
77
|
+
* Possible aliasing of paths per function, bolt or global
|
78
|
+
* Possible irb builder using bond
|
data/Rakefile
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
2
|
begin
|
5
3
|
require 'rcov/rcovtask'
|
6
4
|
|
@@ -11,21 +9,24 @@ begin
|
|
11
9
|
t.verbose = true
|
12
10
|
end
|
13
11
|
rescue LoadError
|
14
|
-
puts "Rcov not available. Install it for rcov-related tasks with: sudo gem install rcov"
|
15
12
|
end
|
16
13
|
|
17
14
|
begin
|
18
15
|
require 'jeweler'
|
16
|
+
require File.dirname(__FILE__) + "/lib/lightning/version"
|
17
|
+
|
19
18
|
Jeweler::Tasks.new do |s|
|
20
19
|
s.name = "lightning"
|
21
|
-
s.
|
22
|
-
s.
|
23
|
-
s.
|
20
|
+
s.version = Lightning::VERSION
|
21
|
+
s.executables = ['lightning', 'lightning-complete', 'lightning-translate']
|
22
|
+
s.summary = "Lightning is a commandline framework that generates shell functions which wrap around commands to autocomplete and translate full paths by their basenames."
|
23
|
+
s.description = "Lightning is a commandline framework that changes how you use paths in your filesystem. Lightning generates shell functions which wrap any command with the ability to autocomplete and interpret paths simply by their basenames. With these functions you don't have to ever type the full path to any file for any command again."
|
24
24
|
s.email = "gabriel.horner@gmail.com"
|
25
|
-
s.homepage = "http://
|
25
|
+
s.homepage = "http://tagaholic.me/lightning"
|
26
26
|
s.authors = ["Gabriel Horner"]
|
27
|
-
s.files = FileList["CHANGELOG.rdoc", "Rakefile",
|
28
|
-
s.has_rdoc =
|
27
|
+
s.files = FileList["CHANGELOG.rdoc", "Rakefile","README.rdoc", "LICENSE.txt", "{bin,lib,test}/**/*"]
|
28
|
+
s.has_rdoc = 'yard'
|
29
|
+
s.rdoc_options = ['--title', "Lightning #{Lightning::VERSION} Documentation"]
|
29
30
|
s.rubyforge_project = 'tagaholic'
|
30
31
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
31
32
|
end
|
@@ -34,36 +35,9 @@ rescue LoadError
|
|
34
35
|
puts "Jeweler not available. Install it for jeweler-related tasks with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
-
t.libs << 'lib'
|
39
|
-
t.pattern = 'test/**/*_test.rb'
|
40
|
-
t.verbose = false
|
41
|
-
end
|
42
|
-
|
43
|
-
Rake::RDocTask.new do |rdoc|
|
44
|
-
rdoc.rdoc_dir = 'rdoc'
|
45
|
-
rdoc.title = 'test'
|
46
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
47
|
-
rdoc.rdoc_files.include('README*')
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
-
end
|
50
|
-
|
51
|
-
namespace :dev do
|
52
|
-
desc "Generates completion, modifies it for local development"
|
53
|
-
task :reload=>:generate_completions do
|
54
|
-
file = 'lightning_completions'
|
55
|
-
string = File.read(file)
|
56
|
-
string.sub!(/^LBIN_PATH/,'#LBIN_PATH')
|
57
|
-
string.sub!(/^#LBIN_PATH/,'LBIN_PATH')
|
58
|
-
File.open(file,'w') {|f| f.write(string) }
|
59
|
-
end
|
38
|
+
task :default => :test
|
60
39
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
require 'lightning'
|
65
|
-
Lightning::Generator.generate_completions 'lightning_completions'
|
66
|
-
end
|
40
|
+
desc 'Run specs with unit test style output'
|
41
|
+
task :test do |t|
|
42
|
+
sh 'bacon -q -Ilib test/*_test.rb'
|
67
43
|
end
|
68
|
-
|
69
|
-
task :default => :test
|
data/bin/lightning
ADDED
data/bin/lightning-complete
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# == Description
|
4
|
-
# Used to complete a lightning command
|
5
3
|
require File.expand_path(File.join(File.dirname(__FILE__), "..","lib","lightning"))
|
6
|
-
|
7
|
-
if (command = ARGV.shift)
|
8
|
-
puts Lightning.complete(command, ENV["COMP_LINE"])
|
9
|
-
exit 0
|
10
|
-
else
|
11
|
-
puts "No command given"
|
12
|
-
exit 1
|
13
|
-
end
|
4
|
+
Lightning::Commands.run_command :complete, ARGV
|
data/lib/lightning.rb
CHANGED
@@ -1,68 +1,54 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
|
2
|
-
require 'yaml'
|
3
1
|
require 'lightning/bolt'
|
4
|
-
require 'lightning/
|
2
|
+
require 'lightning/util'
|
3
|
+
require 'lightning/commands_util'
|
4
|
+
require 'lightning/commands'
|
5
5
|
require 'lightning/completion'
|
6
6
|
require 'lightning/config'
|
7
|
+
require 'lightning/function'
|
7
8
|
require 'lightning/completion_map'
|
9
|
+
require 'lightning/builder'
|
10
|
+
require 'lightning/generators'
|
8
11
|
require 'lightning/generator'
|
12
|
+
require 'lightning/version'
|
9
13
|
|
10
|
-
|
11
|
-
TEST_FLAG = '-test'
|
14
|
+
module Lightning
|
12
15
|
class<<self
|
13
|
-
attr_accessor :
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def load_read_only_config
|
19
|
-
@config = Config.create(:read_only=>true)
|
16
|
+
attr_accessor :config, :functions
|
17
|
+
|
18
|
+
# @return [Config] Contains all user configuration
|
19
|
+
def config
|
20
|
+
@config ||= Config.new
|
20
21
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
# @return [Hash] Maps bolt names to Bolt objects
|
24
|
+
def bolts
|
25
|
+
@bolts ||= Hash.new {|h,k| h[k] = Bolt.new(k) }
|
24
26
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@
|
29
|
-
if bolt_key = config_command(command)['bolt_key']
|
30
|
-
Completion.complete(text_to_complete, bolt_key)
|
31
|
-
else
|
32
|
-
["#Error: No paths found for this command.", "If this is a bug contact me."]
|
33
|
-
end
|
27
|
+
|
28
|
+
# @return [Hash] Maps function names to Function objects
|
29
|
+
def functions
|
30
|
+
@functions ||= create_functions
|
34
31
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
'#Error-no_paths_found_for_this_command'
|
32
|
+
|
33
|
+
# @return [String] Directory for most of lightning's files, ~/.lightning
|
34
|
+
def dir
|
35
|
+
@dir ||= begin
|
36
|
+
require 'fileutils'
|
37
|
+
FileUtils.mkdir_p File.join(home, '.lightning')
|
38
|
+
File.join(home, '.lightning')
|
43
39
|
end
|
44
40
|
end
|
45
|
-
|
46
|
-
def bolts
|
47
|
-
@bolts ||= Bolts.new
|
48
|
-
end
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
puts "Command '#{name}' not found"
|
54
|
-
nil
|
55
|
-
else
|
56
|
-
command
|
57
|
-
end
|
42
|
+
# @return [String] User's home directory, ~
|
43
|
+
def home
|
44
|
+
@home ||= Util.find_home
|
58
45
|
end
|
59
46
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@ignore_paths
|
47
|
+
protected
|
48
|
+
def create_functions
|
49
|
+
config.bolts.inject({}) {|h,(k,v)|
|
50
|
+
bolts[k].generate_functions.each {|f| h[f['name']] = Function.new(f) } ; h
|
51
|
+
}
|
66
52
|
end
|
67
53
|
end
|
68
54
|
end
|
data/lib/lightning/bolt.rb
CHANGED
@@ -1,33 +1,60 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Lightning
|
2
|
+
# A Bolt object is mainly a user-defined set of globs required by a {Function} object to translate paths.
|
3
|
+
#
|
4
|
+
# == Globs
|
5
|
+
# Globs are interpreted by Dir.glob and are fairly similar to shell globs. Some glob examples:
|
6
|
+
#
|
7
|
+
# * Files ending with specific file extensions for a given directory.
|
8
|
+
# "/some/path/*.{rb,erb}"-> Matches files ending with .rb or .erb
|
9
|
+
#
|
10
|
+
# * Files and directories that don't start with specific letters.
|
11
|
+
# "[^ls]*" -> Matches anything not starting with l or s
|
12
|
+
#
|
13
|
+
# * All directories, however many levels deep, under the current directory.
|
14
|
+
# "**/"
|
3
15
|
class Bolt
|
4
|
-
|
5
|
-
|
6
|
-
|
16
|
+
# @return [String] Unique alphanumeric name
|
17
|
+
attr_reader :name
|
18
|
+
# @return [Hash] Maps aliases to full paths. Aliases are valid for a bolt's functions
|
19
|
+
attr_reader :aliases
|
20
|
+
# @return [Boolean] When true adds global commands to list of commands used to generate a bolt's functions
|
21
|
+
attr_reader :global
|
22
|
+
# @return [Array] User-defined globs that are translated by Dir.glob().
|
23
|
+
attr_accessor :globs
|
24
|
+
# Used to generate functions.
|
25
|
+
# @return [Array<Hash, String>] An array element can be a hash of function attributes or a shell command
|
26
|
+
attr_accessor :functions
|
27
|
+
def initialize(name)
|
28
|
+
@name = name
|
29
|
+
@globs = []
|
30
|
+
@functions = []
|
31
|
+
@aliases = {}
|
32
|
+
(Lightning.config.bolts[@name] || {}).each do |k,v|
|
33
|
+
instance_variable_set("@#{k}", v)
|
34
|
+
end
|
7
35
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
36
|
+
|
37
|
+
# Generates functions from a bolt's functions and global shell commands
|
38
|
+
# @return [Array]
|
39
|
+
def generate_functions
|
40
|
+
@functions += Lightning.config.global_commands if @global
|
41
|
+
@functions.inject({}) {|acc, e|
|
42
|
+
cmd = e.is_a?(Hash) ? e.dup : {'shell_command'=>e}
|
43
|
+
cmd['bolt'] = self
|
44
|
+
cmd['name'] ||= function_name(cmd['shell_command'])
|
45
|
+
acc[cmd['name']] ||= cmd if cmd['shell_command']
|
46
|
+
acc
|
47
|
+
}.values
|
11
48
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
:aliases=>Lightning.config_command(Lightning.current_command)['aliases'])
|
49
|
+
|
50
|
+
# Creates function name for a bolt given a shell command
|
51
|
+
def function_name(scmd)
|
52
|
+
Lightning.config.function_name(scmd, alias_or_name)
|
17
53
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#TODO
|
23
|
-
# if (regex = Lightning.config_command(Lightning.current_command)['completion_regex'])
|
24
|
-
# basename = basename[/#{regex}/]
|
25
|
-
# end
|
26
|
-
completion_map[basename] || ''
|
27
|
-
end
|
28
|
-
|
29
|
-
def paths
|
30
|
-
@paths ||= Lightning.config[:paths][key] || []
|
54
|
+
|
55
|
+
protected
|
56
|
+
def alias_or_name
|
57
|
+
@alias || @name
|
31
58
|
end
|
32
59
|
end
|
33
60
|
end
|