Permalink
Browse files

• Implement completion for local, global and instance variables.

  • Loading branch information...
1 parent 574e380 commit 88657bbff246e8611d09e5d18f8f68749ba649e4 @mkhl mkhl committed Jan 22, 2009
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/rush/shell.rb
View
@@ -112,6 +112,8 @@ def path_parts(input) # :nodoc:
$~.to_a.slice(1, 4).push($~.pre_match)
when /((?:@{1,2}|\$|)\w+(?:\[[^\]]+\])*)(\.)(\w*)$/
$~.to_a.slice(1, 3).push($~.pre_match)
+ when /((?:@{1,2}|\$|)\w+)$/
+ $~.to_a.slice(1, 1).push(nil).push($~.pre_match)
else
[ nil, nil, nil ]
end
@@ -146,6 +148,17 @@ def complete_path(possible_var, accessor, quote, partial_path, pre) # :nodoc:
end
end
+ def complete_variable(partial_name, pre)
+ lvars = eval('local_variables', @pure_binding)
+ gvars = eval('global_variables', @pure_binding)
+ ivars = eval('instance_variables', @pure_binding)
+ (lvars + gvars + ivars).select do |e|
+ e.match(/^#{Regexp.escape(partial_name)}/)
+ end.map do |e|
+ (pre || '') + e
+ end
+ end
+
# Try to do tab completion on dir square brackets and slash accessors.
#
# Example:
@@ -164,6 +177,8 @@ def completion_proc
complete_path(receiver, accessor, *rest)
when /^\.$/
complete_method(receiver, accessor, *rest)
+ when nil
+ complete_variable(receiver, *rest)
end
end
end

0 comments on commit 88657bb

Please sign in to comment.