Skip to content

Instantly share code, notes, and snippets.

@twerth
Created August 5, 2010 21:40
Show Gist options
  • Save twerth/510424 to your computer and use it in GitHub Desktop.
Save twerth/510424 to your computer and use it in GitHub Desktop.
Skeleton for bash completion ruby script
#!/usr/bin/env ruby
# To use, put this in your bashrc:
# complete -C path/to/script -o default your_command_or_commands_here
# example, to complete the foo and bar commands with the foo.rb script: complete -C ~/bin/foo.rb -o default foo bar
prefix = ARGV[1]
words = `some command here, or just any array`.split.uniq
words = words.select {|w| /^#{Regexp.escape prefix}/ =~ w} if prefix
puts words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment