On Mar 3, 2007, at 04:33, George Ogata wrote:
> On 2/24/07, Michael Schuerig <michael / schuerig.de> wrote:
>>
>> To my surprise there apparently hasn't been support for bash command
>> line completion for the gem command. I've cobbled together a file  
>> that
>> add just that. See
>>
>> http://schuerig.de/michael/blog/index.php/2007/02/24/gem-bash- 
>> completion/
>>
>> I've only tested it on Debian/Linux, on other Linux/Unix variants  
>> things
>> might work somewhat differently. Also, I don't even try to do
>> completion for gem names; doing that for remote gems would be much to
>> slow and I haven't looked into getting that information from the  
>> local
>> source_cache.
>
> I've had a go at hacking in gem name completion for install and
> uninstall.  For uninstall it uses installed names, for install it uses
> the names in the source cache.  Only tested with gem 0.9.1.
>
> # Michael Schuerig, michael / schuerig.de, 2007-02-24
> # George Ogata, george.ogata / gmail.com, 2007-03-01
> # Free for all uses.
>
> GEM_CACHE_FILE=`ruby -rubygems -rrubygems/source_info_cache \
>                 -e 'print Gem::SourceInfoCache.new.cache_file'`
> GEM_AVAILABLE_FILE=`dirname $GEM_CACHE_FILE`/source_cache_names
>
> #
> # Output all available gem names.
> #
> function available_gems {
>    if [ ! -e $GEM_AVAILABLE_FILE -o \
>         $GEM_CACHE_FILE -nt $GEM_AVAILABLE_FILE ]; then
>        ruby <<EOF > $GEM_AVAILABLE_FILE
>            require 'rubygems/source_info_cache_entry'
>            text = File.read('$GEM_CACHE_FILE')
>            names = Marshal.load(text).values.map do |entry|
>              entry.source_index.latest_specs.keys
>            end.flatten
>            puts names.uniq
> EOF
>    fi
>
>    cat $GEM_AVAILABLE_FILE
> }

RubyGems needs a way to get the source_cache information without  
updating :/  I should file myself a bug.