lib/lightning/completion.rb in cldwalker-lightning-0.1.2 vs lib/lightning/completion.rb in cldwalker-lightning-0.2.0
- old
+ new
@@ -10,12 +10,25 @@
@text_typed = text_typed
@bolt_key = bolt_key
end
def matches
- possible_completions.select do |e|
- e[0, typed.length] == typed
+ if Lightning.config[:complete_regex]
+ begin
+ possible_completions.grep(/#{blob_to_regex(typed)}/)
+ rescue RegexpError
+ ['Error: Invalid regular expression']
+ end
+ else
+ possible_completions.select do |e|
+ e[0, typed.length] == typed
+ end
end
+ end
+
+ #just converts * to .* to make a glob-like regex
+ def blob_to_regex(string)
+ string.gsub(/^\*|([^\.])\*/) {|e| $1 ? $1 + ".*" : ".*" }
end
def typed
# @text_typed[/\s(.+?)$/, 1] || ''
text = @text_typed[/^(\S+)\s+(#{Lightning::TEST_FLAG})?\s*(.+?)$/, 3] || ''