Skip to content

Instantly share code, notes, and snippets.

@dpogorzelski
Created May 30, 2012 23:18
Show Gist options
  • Save dpogorzelski/2839514 to your computer and use it in GitHub Desktop.
Save dpogorzelski/2839514 to your computer and use it in GitHub Desktop.
Command and arguments completion with readline.
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