Google Groups Home
Help | Sign in
Bash completion for the gem command
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Michael Schuerig  
View profile
 More options Feb 23 2007, 8:52 pm
From: Michael Schuerig <mich...@schuerig.de>
Date: Sat, 24 Feb 2007 10:52:36 +0900
Local: Fri, Feb 23 2007 8:52 pm
Subject: [ANN] Bash completion for the gem command

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-complet...

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.

Michael

--
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Hurst  
View profile
 More options Feb 26 2007, 2:42 pm
From: Thomas Hurst <tom.hu...@clara.net>
Date: Tue, 27 Feb 2007 04:42:28 +0900
Local: Mon, Feb 26 2007 2:42 pm
Subject: Re: [ANN] Bash completion for the gem command
* Michael Schuerig (mich...@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-complet...

> 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 have this in my tcsh completions.rc, it provides basic command
completion and completion for installed gems:

  set gemcommands=(build cert check cleanup repository contents \
      dependency environment help install list outdated pristine \
      query rdoc search sources specification uninstall unpack \
      update repository)
  complete gem 'p/1/$gemcommands/' 'n/help/$gemcommands/' \
               'p%*%D:/usr/local/lib/ruby/gems/1.8/gems/% %' 'n/*/f:*/'

I haven't bothered with option completion, but of course that can be
added with a similar effort to yours.

Remote gems should indeed be doable; it would mostly need a fast command
to dump a list of gem names, or have something write them to a text file
beforehand.  If the full list is too big for that to be reasonable, the
plaintext index could be split by prefix.

--
Thomas 'Freaky' Hurst
    http://hur.st/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
George Ogata  
View profile
 More options Mar 3 2007, 7:33 am
From: "George Ogata" <george.og...@gmail.com>
Date: Sat, 3 Mar 2007 21:33:02 +0900
Local: Sat, Mar 3 2007 7:33 am
Subject: Re: [ANN] Bash completion for the gem command
On 2/24/07, Michael Schuerig <mich...@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-complet...

> 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.

> Michael

Hi Michael,

Thanks for the script.

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.

Regards,
George.

----------------------------------------------------------------------

# Michael Schuerig, mich...@schuerig.de, 2007-02-24
# George Ogata, george.og...@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

}

#
# Output all installed gem names.
#
function installed_gems {
    ruby <<EOF
        require 'rubygems'
        names = Gem::SourceIndex.from_installed_gems.map do |name, spec|
          spec.name
        end.uniq
        puts names
EOF

}

_gem()
{
    local cur prev completions

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    COMMANDS='build cert check cleanup contents dependency\
      environment help install list query rdoc search specification\
      uninstall unpack update'

    COMMON_OPTIONS='\
      --source
      -p --http-proxy --no-http-proxy\
      -h --help\
      --config-file\
      --backtrace\
      --debug'

    CERT_OPTIONS='\
      -a -add\
      -l --list\
      -r --remove\
      -b --build\
      -C --certificate\
      -K --private-key\
      -s --sign'

    CHECK_OPTIONS='\
      -v --verify\
      -a --alien\
      -t --test\
      -V --version'

    CLEANUP_OPTIONS='\
      -d --dry-run'

    CONTENTS_OPTIONS='\
      -l --list\
      -V --version\
      -s --spec-dir\
      -v --verbose'

    DEPENDENCY_OPTIONS='\
      -v --version\
      -r --reverse-dependencies --no-reverse-dependencies\
      -p --pipe'

    HELP_OPTIONS=$COMMANDS

    INSTALL_OPTIONS='\
      -v --version\
      -l --local\
      -r --remote\
      -b --both\
      -i --install-dir\
      -B --build-root\
      -d --rdoc --no-rdoc\
      --ri --no-ri\
      -f --force --no-force\
      -t --test --no-test\
      -w --wrappers --no-wrappers\
      -P --trust-policy\
      --ignore-dependencies\
      -y --include-dependencies'

    LIST_OPTIONS='\
      -d --details --no-details\
      -l --local\
      -r --remote\
      -b --both'

    QUERY_OPTIONS='\
      -n --name-matches\
      -d --details --no-details\
      -l --local\
      -r --remote\
      -b --both'

    RDOC_OPTIONS='\
      --all\
      --rdoc --no-rdoc\
      --ri --no-ri\
      -v --version'

    SEARCH_OPTIONS='\
      -d --details --no-details\
      -l --local\
      -r --remote\
      -b --both'

    SPECIFICATION_OPTIONS='\
      -v --version\
      -l --local\
      -r --remote\
      -b --both\
      -all'

    UNINSTALL_OPTIONS='\
      -a --all --no-all\
      -i --ignore-dependencies --no-ignore-dependencies\
      -x --executables --no-executables\
      -v --version'

    UNPACK_OPTIONS='\
      -v --version'

    UPDATE_OPTIONS='\
      -i --install-dir\
      -B --build-root\
      -d --rdoc --no-rdoc\
      -ri --no-ri\
      -f --force --no-force\
      -t --test --no-test\
      -w --wrappers --no-wrappers\
      -P --trust-policy\
      --ignore-dependencies\
      -y --include-dependencies\
      --system'

    case "${prev}" in
      build)
        completions="$COMMON_OPTIONS $BUILD_OPTIONS"
        ;;
      cert)
        completions="$COMMON_OPTIONS $CERT_OPTIONS"
        ;;
      check)
        completions="$COMMON_OPTIONS $CHECK_OPTIONS"
        ;;
      cleanup)
        completions="$COMMON_OPTIONS $CLEANUP_OPTIONS"
        ;;
      contents)
        completions="$COMMON_OPTIONS $CONTENTS_OPTIONS"
        ;;
      dependency)
        completions="$COMMON_OPTIONS $DEPENDENCY_OPTIONS"
        ;;
      environment)
        completions="$COMMON_OPTIONS $ENVIRONMENT_OPTIONS"
        ;;
      help)
        completions="$COMMON_OPTIONS $HELP_OPTIONS"
        ;;
      install)
        completions="$COMMON_OPTIONS $INSTALL_OPTIONS `available_gems`"
        ;;
      list)
        completions="$COMMON_OPTIONS $LIST_OPTIONS"
        ;;
      query)
        completions="$COMMON_OPTIONS $QUERY_OPTIONS"
        ;;
      rdoc)
        completions="$COMMON_OPTIONS $RDOC_OPTIONS"
        ;;
      search)
        completions="$COMMON_OPTIONS $SEARCH_OPTIONS"
        ;;
      specification)
        completions="$COMMON_OPTIONS $SPECIFICATION_OPTIONS"
        ;;
      uninstall)
        completions="$COMMON_OPTIONS $UNINSTALL_OPTIONS `installed_gems`"
        ;;
      unpack)
        completions="$COMMON_OPTIONS $UNPACK_OPTIONS"
        ;;
      update)
        completions="$COMMON_OPTIONS $UPDATE_OPTIONS"
        ;;
      *)
        completions="$COMMANDS $COMMON_OPTIONS"
        ;;
    esac

    COMPREPLY=( $( compgen -W "$completions" -- $cur ))
    return 0

}

[ -n "${have:-}" ] && complete -F _gem $filenames gem

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Hodel  
View profile
 More options Mar 5 2007, 4:24 pm
From: Eric Hodel <drbr...@segment7.net>
Date: Tue, 6 Mar 2007 06:24:20 +0900
Local: Mon, Mar 5 2007 4:24 pm
Subject: Re: [ANN] Bash completion for the gem command
On Mar 3, 2007, at 04:33, George Ogata wrote:

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

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google