Created
May 30, 2012 23:18
-
-
Save dpogorzelski/2839514 to your computer and use it in GitHub Desktop.
Command and arguments completion with readline.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COMMANDS = { | |
'collect' => ['info', 'info2'], | |
'watch' => ['watchvalue_1', 'watchvalue_2'] | |
} | |
comp = proc do |s| | |
if Readline.line_buffer =~ /#{COMMANDS.keys} / | |
COMMANDS.values_at("#{Readline.line_buffer.gsub(/ .*/,'')}").flatten.grep(/^#{Regexp.escape(s)}/) | |
else | |
COMMANDS.keys.grep(/^#{Regexp.escape(s)}/) | |
end | |
end | |
Readline.completion_proc = comp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment