summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Walker <ka0ttic@gentoo.org>2005-01-18 00:16:05 +0000
committerAaron Walker <ka0ttic@gentoo.org>2005-01-18 00:16:05 +0000
commitaadec15a040dfd44d88bbbedb25750fe7243bebb (patch)
tree4de918288badcab38384c7bbbecc374d35e92813
downloadgentoo-bashcomp-aadec15a040dfd44d88bbbedb25750fe7243bebb.tar.gz
gentoo-bashcomp-aadec15a040dfd44d88bbbedb25750fe7243bebb.tar.bz2
gentoo-bashcomp-aadec15a040dfd44d88bbbedb25750fe7243bebb.zip
svn path=/trunk/; revision=1
-rw-r--r--AUTHORS17
-rw-r--r--COPYING340
-rw-r--r--TODO118
-rw-r--r--gentoo969
4 files changed, 1444 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..6ef3f5f
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,17 @@
+Maintainer:
+Zach Forrest <zorder@users.sourceforge.net>
+Aaron Walker <ka0ttic@gentoo.org>
+
+Authors:
+Geert Bevin <gbevin@theleaf.be> (original author)
+Zach Forrest <zorder@users.sourceforge.net>
+
+Contributors:
+Ed Catmur <ed@catmur.co.uk> - absolute path patch, init.d completion, _ebuild() fixes
+Peter Jensen <gentoo-bugs@pekaje.homeip.net> - equery completion
+Ciaran McCreesh <ciaranm@gentoo.org> - sed command for _portdir function, ekeyword completion
+
+Note:
+Modifications were made in a version of this script found in
+'app-shells/bash-completion-20040526', but I don't know who to
+credit. Please let me know who you are if you read this. Thanks.
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..60549be
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) 19yy <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19yy name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..8e097cb
--- /dev/null
+++ b/TODO
@@ -0,0 +1,118 @@
+# -*- shell-script -*-
+#
+# Gentoo Linux command completion -- FEATURES (COMMANDS) TO BE ADDED.
+#
+# $Id: TODO,v 1.3 2004/06/03 01:04:41 zorder Exp $
+#
+# Copyright 1999-2004 Gentoo Technologies, Inc.
+# Distributed under the terms of the GNU General Public License, v2 or later
+
+#
+# etcat completion command
+#
+have etcat && {
+_etcat()
+{
+ # -b </path/to/file> [category]
+ # belongs </path/to/file> [category]
+ # Searches for the package which a file belongs to with an option
+ # to restrict a search to a single or multiple category. Wildcards
+ # in the category name is accepted to speed up searching.
+ # (eg. etcat belongs /usr/lib/libmpeg.so "media-*")
+ #
+ # -c <package[-version]>
+ # changes <package[-version]>
+ # Outputs ChangeLog entry for the package and version specified.
+ # Uses the latest package version if none specified.
+ #
+ # -d <regex expression>
+ # depends <regex expression>
+ # Searches through portage for a dependency string satisfying that
+ # regular expression.
+ #
+ # -f <package[-version]>
+ # files <package[-version]>
+ # Lists all the files installed for this package.
+ #
+ # -s <package>
+ # size <package>
+ # Outputs the installed size of the package.
+ #
+ # -u <package[-version]>
+ # uses <package[-version]>
+ # Outputs the USE flags supported by this package and also their
+ # installed state and description.
+ #
+ # -v <package>
+ # versions <package>
+ # Output all the versions for packages that match the package name
+ # given with indication of whether the packages is stable, masked,
+ # unstable or installed.
+
+}
+complete -F _etcat etcat
+}
+
+# epm completion command
+#
+have epm && {
+_epm()
+{
+
+}
+complete -F _epm epm
+}
+
+#
+# euse completion command
+#
+have euse && {
+_euse()
+{
+# DESCRIPTION
+# euse is used to set(disable/enable) USE flags /etc/make.conf without having to edit the file directly. It is also used to
+# get detail information about use flags like description, status of flags(enabled/disabled), type of flag(global/local)
+# etc. It can also be queried for viewing the current use flag settings in /etc/make.conf, /etc/make.defaults and environ-
+# ment.
+# OPTIONS
+# -c, --conf
+# Print the USE flag setting in /etc/make.conf
+# -d, --defaults
+# Print the USE flag setting in /etc/make.profile/make.defaults
+# -e, --env
+# Print the USE flag setting in environment
+# -E, --enable
+# Enables USE flag(s) in make.conf. It accepts one or more USE flags space separted as parameters. Please read
+# README for all the different cases it handles.
+# -D, --disable
+# Disables USE flag(s) in make.conf. Puts a '-' sign infront of the use flag and appends to USE setting of
+# make.conf. It accepts one or more USE flags space separted as parameters. Please read README for all the different
+# cases it handles.
+# -i, --info
+# Prints detail information about the USE flag(s). If no arguments are given then all the USE flag(global & local)
+# information is printed. If one or more arguments are given(space separated) then information of only those flags
+# are printed.
+# The output is in the following format:
+# alpha [-] [ ] [G] indicates that architecture ...
+# moznocompose [+] [C] [L] [net-www/mozilla] : If you ...
+# The column descriptions are:
+# flag_name
+# name of the use flag
+# flag_status
+# indicates whether the USE flag is enabled or disabled. - indicates disabled, + indicates enabled.
+# flag_location
+# indicates where the USE flag is enabled or disabled. C indicates make.conf, D indicates make.defaults, E
+# indicates environment.
+# flag_type
+# indicates if the flag is global USE flag or a local USE flag.If it is local USE flag, then the description
+# column begins with the package which it belongs to in square brackets. See moznocompose example above.
+# description
+# gives a short description of the USE flag
+# -h, --help
+# Show the help message listing all the available flags and a short description
+# -v, --version
+# Show the version information
+
+}
+complete -F _euse euse
+}
diff --git a/gentoo b/gentoo
new file mode 100644
index 0000000..da7cc74
--- /dev/null
+++ b/gentoo
@@ -0,0 +1,969 @@
+# Gentoo Linux Bash Shell Command Completion
+#
+# $Id: gentoo,v 1.22 2005/01/12 11:14:28 ka0ttic Exp $
+#
+# Copyright 1999-2005 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License, v2 or later
+
+#
+# Retrieve PORTDIR location from user's make.conf or, if it is not defined
+# there, from make.globals.
+#
+_portdir()
+{
+ sed -n -e '/^PORTDIR=/ { s/^[^=]\+="\?\([^"]\+\|\S\+\).*/\1/p ; q }' \
+ /etc/make.conf /etc/make.globals
+}
+
+#
+# emerge completion command
+#
+have emerge && {
+_emerge()
+{
+ local cur curword numwords compwords opts cond prepend
+ local words grepcmd sedcmd stopre stophere i
+ local action actionpos actionre sysactions eactions pkgpos
+ local version_mode searchdesc_mode help_mode resume_mode
+ local portdir=$(_portdir)
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ numwords=${#COMP_WORDS[*]}
+ curword=${COMP_CWORD}
+ compwords="${COMP_WORDS[*]}"
+ actionre=' (-[CPcis]|(metadata|s(y(nc|stem)|earch)|regen|(unmerg|prun)e|world|((dep)?clean)|(in(fo|ject))))\b'
+ stopre=' (depclean|info|metadata|regen|sy(nc|stem)|world|--(resume|s(kipfirst|ync)))\b'
+ opts=''
+ # Test for action.
+ action=$(echo "${compwords}" | egrep -o --regex="${actionre}" | tr -d ' ')
+ if [[ "${action}" ]]; then
+ for ((i = 0; i < ${numwords}; i++ )); do
+ if [[ "${COMP_WORDS[${i}]}" == "${action}" ]]; then
+ actionpos=${i}
+ pkgpos=$((actionpos + 1))
+ break
+ fi
+ done
+ if [ ${#action} -eq 2 ]; then
+ case "${action}" in
+ '-C') action='unmerge' ;;
+ '-P') action='prune' ;;
+ '-c') action='clean' ;;
+ '-i') action='inject' ;;
+ '-s') action='search' ;;
+ esac
+ fi
+ else
+ for ((i = 1; i < ${numwords}; i++ )); do
+ if [[ ! "${COMP_WORDS[$i]}" == -* ]]; then
+ pkgpos=${i}
+ break
+ fi
+ done
+ [[ "${pkgpos}" ]] || pkgpos=${numwords}
+ fi
+ # Check for special cases.
+ version_mode=$(echo "${compwords}" | egrep -o -regexp=" -(V|-version)\b")
+ searchdesc_mode=$(echo "${compwords}" | egrep -o --regexp=" -(S|-searchdesc)\b")
+ help_mode=$(echo "${compwords}" | egrep -o --regexp=" -(h|-help)\b")
+ # Handle special cases.
+ if [[ "${action}" = 'search' ]] || [[ "${searchdesc_mode}" ]] || \
+ [[ "${version_mode}" ]] || [[ "${action}" = 'metadata' ]]; then
+ unset COMPREPLY
+ return 0
+ elif [[ "${help_mode}" ]]; then
+ unset COMPREPLY
+ [ ${curword} -eq 2 ] && COMPREPLY=($(compgen -W 'config sync system' -- ${cur}))
+ return 0
+ fi
+ # Complete on options.
+ if [[ "${cur}" == -* ]]; then
+ # If a resume option was specified, it needs special handling.
+ resume_mode=$(echo "${compwords}" | egrep -o --regexp=" --(resume|skipfirst)\b")
+ if [[ "${resume_mode}" ]]; then
+ if [[ "${cur}" == --* ]]; then
+ opts="--ask --pretend --resume --skipfirst"
+ elif [[ "${cur}" == -* ]]; then
+ [[ -z $(echo "${compwords}" | egrep -o --regexp=" --(ask|pretend)\b") ]] && opts="-a -p"
+ fi
+ elif [[ "${cur}" == --* ]]; then
+ # Complete on long options.
+ opts="--ask --autoclean \
+ --buildpkg --buildpkgonly \
+ --changelog --clean --columns \
+ --debug --deep \
+ --emptytree \
+ --fetch-all-uri --fetchonly \
+ --getbinpkg --getbinpkgonly \
+ --newuse --noconfmem --nodeps --noreplace --nospinner
+ --oneshot --onlydeps \
+ --pretend \
+ --quiet \
+ --sync \
+ --tree \
+ --update --upgradeonly --usepkg --usepkgonly \
+ --verbose"
+ if [ ${curword} -eq 1 ] && [ ${numwords} -eq 2 ]; then
+ opts="${opts} --help --resume --searchdesc --version"
+ fi
+ elif [[ "${cur}" == -* ]]; then
+ # Complete on short options.
+ opts="-B -D -G -K -O -U -a -b -d -e -f -g -k -l -n -o -p -q -t -u -v"
+ if [ ${curword} -eq 1 ] && [ ${numwords} -eq 2 ]; then
+ opts="${opts} -h -S -V"
+ fi
+ if [[ -z "${action}" ]] && [ ${curword} -eq $((pkgpos - 1)) ]; then
+ opts="${opts} -C -P -c -i -s"
+ fi
+ fi
+ # Generate the reply.
+ COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
+ # NOTE: This slows things down!
+ # (Adapted from bash_completion by Ian Macdonald <ian@caliban.org>)
+ # This removes any options from the list of completions that have
+ # already been specified on the command line.
+ COMPREPLY=($(echo "${COMP_WORDS[@]}" | \
+ (while read -d ' ' i; do
+ [ "${i}" == "" ] && continue
+ # flatten array with spaces on either side,
+ # otherwise we cannot grep on word boundaries of
+ # first and last word
+ COMPREPLY=" ${COMPREPLY[@]} "
+ # remove word from list of completions
+ COMPREPLY=(${COMPREPLY/ ${i%% *} / })
+ done
+ echo ${COMPREPLY[@]})))
+ return 0
+ fi
+ # Stop completion if a special case is encountered.
+ stophere=$(echo "${compwords}" | egrep -o --regex="${stopre}")
+ if [[ "${stophere}" ]]; then
+ unset COMPREPLY
+ return 0
+ fi
+ # Complete on filenames if given a path.
+ if [[ "${cur} " == @('/'|'.'|'~'|'$')* ]]; then
+ COMPREPLY=($(compgen -G "${cur}*"))
+ return 0
+ fi
+ # Complete on installed packages when unmerging.
+ if [[ "${action}" == 'unmerge' ]]; then
+ grepcmd="grep -E ^$cur.*"
+ if [ "${cur}" ]; then
+ if [ $(echo "${cur}" | grep '/') ]; then
+ words=$(cd /var/db/pkg; compgen -G "${cur}*")
+ else
+ words=$(cd /var/db/pkg; compgen -S '/' -G "${cur}*")
+ [ $(echo "${words}" | ${grepcmd} | grep '/' | wc -l) = 1 ] && \
+ words=$(cd /var/db/pkg; compgen -G "*/*")
+ fi
+ COMPREPLY=($(echo "${words}" | ${grepcmd}))
+ else
+ words=$(cd /var/db/pkg; compgen -X '!*-*' -S '/' -G "${cur}*")
+ COMPREPLY=($(echo "${words}"))
+ fi
+ return 0
+ fi
+ # Check for conditional.
+ cond="${cur%%[A-Za-z0-9]*}"
+ cur="${cur:${#cond}}"
+ [[ "${cond:0:1}" == "'" ]] && prepend="-P ${cond:1}"
+ # Handle cases where a conditional is specified.
+ if [[ "${cond}" ]]; then
+ if [[ "${cur}" ]]; then
+ if [[ "${cur}" == */* ]]; then
+ COMPREPLY=($(cd ${portdir}; compgen ${prepend} -G "${cur}*" -- "${cur}"))
+ # Complete on the specific versions (if appropriate).
+ [[ ${#COMPREPLY[@]} -le 1 ]] && \
+ COMPREPLY=($(cd ${portdir}/metadata/cache; compgen ${prepend} -G "${cur}*" -- "${cur}"))
+ else
+ COMPREPLY=($(cd ${portdir}; compgen ${prepend} -S '/' -G "${cur}*" -- "${cur}"))
+ [[ ${#COMPREPLY[@]} = 1 ]] && \
+ COMPREPLY=($(cd ${portdir}; compgen ${prepend} -G "${cur}*/*" -- "${cur}"))
+ fi
+ else
+ words="$(cd ${portdir}; for i in [a-z]*-[a-z0-9]*; do [ -d $i ] && echo $i; done)"
+ COMPREPLY=($(compgen -W '${words}' -- "${cur}"))
+ fi
+ # If all else fails, try to complete on package names without the
+ # category being specified. Neato!
+ if [[ ! "${COMPREPLY}" ]]; then
+ words="$(cd ${portdir}; for i in [a-z]*-[a-z0-9]*/${cur}*; do [ -d $i ] && echo ${i##*/}; done)"
+ COMPREPLY=($(compgen ${prepend} -W "${words}" -- ${cur}))
+ if [[ ${#COMPREPLY[@]} -le 1 ]]; then
+ # Now complete on the specific versions.
+ words="$(cd ${portdir}/metadata/cache; for i in */${cur}*; do echo ${i##*/}; done)"
+ COMPREPLY=($(compgen ${prepend} -W '${words}' -- "${cur}"))
+ fi
+ fi
+ return 0
+ fi
+ # Complete on packages.
+ grepcmd="grep -E ^${cur}.*"
+ sedcmd="sed -e :^[^-]*$:d"
+ if [ ${COMP_CWORD} -eq 1 ]; then
+ if [ $numwords -le 2 ]; then
+ sysactions=$'\n'"system"$'\n'"world"$'\n'"sync"$'\n'"metadata"
+ else
+ sysactions=$'\n'"system"$'\n'"world"$'\n'"sync"
+ fi
+ else
+ # Only allow these actions if no packages have been specified.
+ #
+ # TODO: This doesn't block these actions if no categories are
+ # specified. Please fix me.
+ #
+ # e.g. emerge -a gentoo-dev-sources
+ #
+ # will still allow system and world actions to be specified,
+ # as opposed to
+ #
+ # emerge -a sys-kernel/gentoo-dev-sources
+ #
+ if [[ ! " ${compwords} " == *" "*[/]*" "* ]]; then
+ sysactions=$'\n'"system"$'\n'"world"
+ else
+ sysactions=''
+ fi
+ fi
+ if [[ ! "${action}" ]] && [ ${curword} -le ${pkgpos} ]; then
+ eactions=$'\n'"clean"$'\n'"depclean"$'\n'"inject"$'\n'"prune"$'\n'"regen"$'\n'"search"$'\n'"unmerge"
+ fi
+ if [ "${cur}" ]; then
+ # Handle absolute paths.
+ # Thanks to Ed Catmur <ed@catmur.co.uk> for pointing this out and
+ # submitting the patch.
+ if [[ "${cur} " == @('/'|'.'|'~'|'$')* ]]; then
+ COMPREPLY=''
+
+ return 0
+ elif [ $(echo "${cur}" | grep '/') ]; then
+ words=$(cd ${portdir}; compgen -G "${cur}*" | ${sedcmd})"${sysactions}""${eactions}"
+ else
+ words=$(cd ${portdir}; compgen -X "!*-*" -S '/' -G "${cur}*" | ${sedcmd})"${sysactions}""${eactions}"
+ [ $(echo "${words}" | ${grepcmd} | grep '/' | wc -l) = 1 ] && \
+ words=$(cd ${portdir}; compgen -G "*/*" | ${sedcmd})"${sysactions}""${eactions}"
+ fi
+ COMPREPLY=($(echo "${words}" | ${grepcmd}))
+ else
+ words="$(cd ${portdir}; for i in [a-z]*-[a-z0-9]*; do [ -d $i ] && echo $i; done)""${sysactions}""${eactions}"
+ COMPREPLY=($(compgen -W "${words}" -- ${cur}))
+ fi
+ # If all else fails, try to complete on package names without the
+ # category being specified. Neato!
+ if [[ ! "${COMPREPLY}" ]]; then
+ words="$(cd ${portdir}; for i in [a-z]*-[a-z0-9]*/${cur}*; do [ -d $i ] && echo ${i##*/}; done)"
+ COMPREPLY=($(compgen -W "${words}" -- ${cur}))
+ fi
+
+ return 0
+}
+complete $filenames -F _emerge emerge
+}
+
+#
+# ebuild completion command
+#
+have ebuild && {
+_ebuild()
+{
+ local cur
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+ if [[ $COMP_CWORD -eq 1 ]]; then
+ COMPREPLY=($(compgen -f -X "!*.ebuild" -- ${cur}) \
+ $(compgen -d -- ${cur}) \
+ $(compgen -W '--debug' -- ${cur}))
+ elif [[ $COMP_CWORD -eq 2 && "${COMP_WORDS[1]}" = "--debug" ]]; then
+ COMPREPLY=($(compgen -f -X "!*.ebuild" -- ${cur}) $(compgen -d -- ${cur}))
+ elif [[ $COMP_CWORD -ge 2 ]]; then
+ COMPREPLY=($(compgen -W 'clean compile config \
+ depend digest \
+ fetch \
+ help \
+ install \
+ merge \
+ package postinst postrm preinst prerm \
+ qmerge \
+ rpm \
+ setup \
+ unmerge unpack' ${cur}))
+ fi
+ return 0
+}
+complete $filenames -F _ebuild ebuild
+}
+
+#
+# Gentoo init.d completion
+#
+
+_gentoo_style_init()
+{
+ local script="${COMP_WORDS[0]}"
+ local cur="${COMP_WORDS[$COMP_CWORD]}"
+
+ if [[ ( -f "${script}" || -h "${script}" ) && -r "${script}" ]] \
+ && [[ "${script}" != *.sh ]] \
+ && [[ "$(head -n 1 "${script}")" = "#!/sbin/runscript" ]]; then
+ [[ $COMP_CWORD -gt 1 ]] && return 1
+ COMPREPLY=($(opts="start stop status restart pause zap ineed needsme iuse usesme broken"; eval "$(grep '^opts=' "${script}")"; echo "${opts}"))
+ [[ "$COMPREPLY" ]] || COMPREPLY=(start stop restart zap)
+ COMPREPLY=($(compgen -W "${COMPREPLY[*]}" -- "${cur}"))
+ else
+ COMPREPLY=($(compgen -o default -- "${cur}"))
+ fi
+ return 0
+}
+complete -F _gentoo_style_init /etc/init.d/*
+
+#
+# rc completion command
+#
+have rc && {
+_rc()
+{
+ local cur
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+ if [ ${#COMP_WORDS[*]} -le 2 ]; then
+ COMPREPLY=($(compgen -W "$(for i in /etc/runlevels/*; do echo ${i##*/}; done)" -- $cur))
+ fi
+ return 0
+}
+complete -F _rc rc
+}
+
+#
+# rc-status completion command
+#
+have rc-status && {
+_rcstatus()
+{
+ local cur
+ cur=${COMP_WORDS[COMP_CWORD]}
+ if [ $COMP_CWORD -eq 1 ]; then
+ if [[ "${cur}" == --* ]]; then
+ COMPREPLY=($(compgen -W '--all --list --unused' -- ${cur}))
+ elif [[ "${cur}" == -* ]]; then
+ COMPREPLY=($(compgen -W '-a -l -u' -- ${cur}))
+ else
+ COMPREPLY=($(compgen -W "$(rc-status --list)" -- ${cur}))
+ fi
+ else
+ unset COMPREPLY
+ fi
+ return 0
+}
+complete -F _rcstatus rc-status
+}
+
+#
+# rc-update completion command
+#
+have rc-update && {
+_rcupdate()
+{
+ local cur show
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ if [ $COMP_CWORD -eq 1 ]; then
+ if [[ "${cur}" == -* ]]; then
+ COMPREPLY=($(compgen -W '-a -d -s' -- ${cur}))
+ else
+ COMPREPLY=($(compgen -W 'add del show' ${cur}))
+ fi
+ else
+ if [ "${COMP_WORDS[1]}" == "show" ] || [ "${COMP_WORDS[1]}" == "-s" ]; then
+ show="TRUE"
+ fi
+ if ([ $COMP_CWORD -eq 3 ] && [ ! "$show" ]) || ([ $COMP_CWORD -eq 2 ] && [ "$show" ]); then
+ COMPREPLY=($(compgen -W "$(for i in /etc/runlevels/*; do echo ${i##*/}; done)" -- $cur))
+ elif [ $COMP_CWORD -eq 2 ]; then
+ COMPREPLY=($(compgen -X "*.@(c|sh|test)" -W "$(for i in /etc/init.d/*; do echo ${i##*/}; done)" $cur))
+ elif [ ${#COMP_WORDS[*]} -gt 2 ] ; then
+ COMPREPLY=($(compgen -W "$(for i in /etc/runlevels/*; do echo ${i##*/}; done)" -- $cur))
+ else
+ unset COMPREPLY
+ fi
+ fi
+ return 0
+}
+complete -F _rcupdate rc-update
+}
+
+#
+# gcc-config completion command
+#
+have gcc-config && {
+_gccconfig()
+{
+ local cur curword numwords opts
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ numwords=${#COMP_WORDS[*]}
+ curword=${COMP_CWORD}
+ opts=""
+ if [ ${numwords} -gt 3 ]; then
+ unset COMPREPLY
+ return 0
+ fi
+ if [[ "${cur}" == -* ]] || [ ${curword} -eq 1 ]; then
+ if [ ${numwords} -le 2 ] && [ ${curword} -eq 1 ]; then
+ opts="--use-old \
+ --use-portage-chost \
+ --get-current-profile \
+ --list-profiles \
+ --print-environ \
+ --get-bin-path \
+ --get-lib-path \
+ --get-stdcxx-incdir"
+ fi
+ elif [ ${numwords} -le 3 ] && [ ${curword} -eq 2 ]; then
+ case "${COMP_WORDS[1]}" in
+ --@(print-environ|get-@(@(bin|lib)-path|stdcxx-incdir)))
+ opts="$(gcc-config --list-profiles | sed -r -e 's/(\[([^]]*)\]) //g')"
+ ;;
+ esac
+ fi
+ COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
+ return 0
+}
+complete -F _gccconfig gcc-config
+}
+
+#
+# distcc-config completion command
+#
+have distcc-config && {
+_distccconfig()
+{
+ local cur curword numwords opts
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ numwords=${#COMP_WORDS[*]}
+ curword=${COMP_CWORD}
+ if [ ${numwords} -gt 3 ]; then
+ unset COMPREPLY
+ return 0
+ fi
+ if [[ "${cur}" == -* ]] || [ ${curword} -eq 1 ]; then
+ if [ ${numwords} -le 2 ] && [ ${curword} -eq 1 ]; then
+ opts="--get-hosts \
+ --get-verbose \
+ --get-log \
+ --set-hosts \
+ --set-verbose \
+ --set-log \
+ --add-path \
+ --no-path"
+ else
+ opts=""
+ fi
+ else
+ opts=""
+ fi
+ COMPREPLY=($(compgen -W "${opts}" | grep ^$cur))
+ return 0
+}
+complete -F _distccconfig distcc-config
+}
+
+#
+# java-config completion command
+#
+have java-config && {
+_javaconfig()
+{
+ local cur prev curword numwords opts args arg spec flag sedcmd grepcmd
+ local multiplepkgs pkgs execopts
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ numwords=${#COMP_WORDS[*]}
+ curword=${COMP_CWORD}
+ opts=""
+ args=""
+ pkgs=""
+ sedcmd="sed -r -e s/\[([^]]+)\].*/\1/"
+ vmsedcmd="sed -r -e s/\[([^]]+)\]/\1/"
+ grepcmd="egrep -o (--set-(system|user)-(classpath|vm)=)"
+ multiplepkgs=""
+ execopts="HtmlConverter JavaPluginControlPanel \
+ appletviewer awt_robot \
+ extcheck \
+ idlj \
+ j2sdk-config jar jarsigner \
+ java java-rmi.cgi java_vm javac javadoc javah javap jdb \
+ keytool kinit klist ktab \
+ native2ascii \
+ oldjava oldjavac oldjdb orbd \
+ policytool \
+ realpath rmic rmid rmiregistry \
+ serialver servertool \
+ tnameserv"
+ if [[ "${cur}" == -* ]] || [ ${curword} -eq 1 ]; then
+ case "${cur}" in
+ --java)
+ opts="--java --javac --java-version"
+ ;;
+ --j@(a@(r|va@(c|-version))|@(dk|re)-home))
+ opts=""
+ ;;
+ --list-available-@(packages|vms))
+ opts=""
+ ;;
+ --@(exec|set-@(user|system)-@(classpath|vm)))
+ opts="${cur}="
+ ;;
+ --set-@(user|system)-@(classpath|vm)=)
+ if [[ "${cur}" == "--set-system-vm=" ]] || [[ "${cur}" == "--set-user-vm=" ]]; then
+ flag="--list-available-vms"
+ args=$(java-config --nocolor "${flag}" | cut --delimiter=' ' --fields=2 | ${vmsedcmd})
+ else
+ flag="--list-available-packages"
+ args=$(java-config --nocolor "${flag}" | ${sedcmd})
+ fi
+ for arg in ${args}; do
+ [ "${opts}" ] && opts="${opts} ${arg}" || opts="${arg}"
+ done
+ COMPREPLY=($(compgen $nospace -W "${opts}"))
+ return 0
+ ;;
+ --exec=)
+ COMPREPLY=($(compgen $nospace -W "${execopts}"))
+ return 0
+ ;;
+ *)
+ if [[ "${cur}" == "--set-system-vm="* ]] || [[ "${cur}" == "--set-user-vm="* ]]; then
+ args=$(java-config --nocolor --list-available-vms | cut --delimiter=' ' --fields=2 | ${vmsedcmd})
+ if [[ "${cur}" == "--set-system-vm="* ]]; then
+ spec=${cur##--set-system-vm=}
+ else
+ spec=${cur##--set-user-vm=}
+ fi
+ for arg in ${args}; do
+ if [[ "${arg:0:${#spec}}" == "${spec}" ]]; then
+ [ "${opts}" ] && opts="${opts} ${arg}" || opts="${arg}"
+ fi
+ done
+ [[ "${opts}" == "${spec}" ]] && opts=""
+ COMPREPLY=($(compgen -W "${opts}"))
+ return 0
+ elif [[ "${cur}" == "--set-system-classpath="* ]] || [[ "${cur}" == "--set-user-classpath="* ]]; then
+ args=$(java-config --nocolor --list-available-packages | ${sedcmd})
+ [ $(echo "${cur}" | grep -c ",") -gt 0 ] && multiplepkgs="true"
+ if [[ "${cur}" == "--set-system-classpath="* ]]; then
+ spec="${cur##--set-system-classpath=}"
+ else
+ spec="${cur##--set-user-classpath=}"
+ fi
+ if [[ "${multiplepkgs}" ]]; then
+ pkgs="${spec%,*}"
+ spec="${spec##*,}"
+ fi
+ if [[ "${multiplepkgs}" ]]; then
+ for arg in ${args}; do
+ if [[ "${spec}" ]]; then
+ if [[ "${arg:0:${#spec}}" == "${spec}" ]] \
+ && [[ ! $(echo "${cur}" | egrep -o "(=|,)${arg},") ]]; then
+ [ "${opts}" ] && opts="${opts} ${pkgs},${arg}" || opts="${pkgs},${arg}"
+ fi
+ else
+ if [[ ! $(echo "${cur}" | egrep -o "(=|,)${arg},") ]]; then
+ [ "${opts}" ] && opts="${opts} ${pkgs},${arg}" || opts="${pkgs},${arg}"
+ fi
+ fi
+ done
+ [[ "${opts}" == "${pkgs},${spec}" ]] && opts=""
+ else
+ for arg in ${args}; do
+ if [[ "${spec}" ]] && [[ "${arg:0:${#spec}}" == "${spec}" ]]; then
+ [ "${opts}" ] && opts="${opts} ${arg}" || opts="${arg}"
+ fi
+ done
+ [[ "${opts}" == "${spec}" ]] && opts=""
+ fi
+ COMPREPLY=($(compgen -W "${opts}"))
+ return 0
+ elif [[ "${cur}" == "--exec="* ]]; then
+ spec=${cur##--exec=}
+ for arg in ${execopts}; do
+ if [[ "${arg:0:${#spec}}" == "${spec}" ]]; then
+ [ "${opts}" ] && opts="${opts} ${arg}" || opts="${arg}"
+ fi
+ done
+ [[ "${opts}" == "${spec}" ]] && opts=""
+ COMPREPLY=($(compgen -W "${opts}"))
+ return 0
+ else
+ opts="--classpath --clean-system-classpath --clean-user-classpath \
+ --exec \
+ --full-classpath \
+ --jar --java --javac --java-version --jdk-home --jre-home \
+ --list-available-packages --list-available-vms \
+ --nocolor \
+ --set-system-classpath --set-system-vm --set-user-classpath --set-user-vm"
+ [[ "$prev" == "--nocolor" ]] && opts="${opts/--nocolor}"
+ fi
+ ;;
+ esac
+ elif [[ "$prev" == "--nocolor" ]] && [ ${curword} -eq 2 ] && [ $numwords -le 3 ]; then
+ opts="--classpath --clean-system-classpath --clean-user-classpath \
+ --exec \
+ --full-classpath \
+ --jar --java --javac --java-version --jdk-home --jre-home \
+ --list-available-packages --list-available-vms \
+ --set-system-classpath --set-system-vm --set-user-classpath --set-user-vm"
+ fi
+ COMPREPLY=($(compgen $nospace -W "${opts}" -- ${cur}))
+ return 0
+}
+complete $nospace -F _javaconfig java-config
+}
+
+#
+# opengl-update completion command
+#
+have opengl-update && {
+_openglupdate()
+{
+ local cur
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ if [ ${#COMP_WORDS[*]} -le 2 ]; then
+ COMPREPLY=($(compgen -W "$(for i in /usr/lib/opengl/*; do [ -d $i ] && echo ${i##*/}; done)" $cur))
+ else
+ unset COMPREPLY
+ fi
+ return 0
+}
+complete -F _openglupdate opengl-update
+}
+
+#
+# browser-config completion command
+#
+have browser-config && {
+_browserconfig()
+{
+ local cur prev
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ if [[ ${COMP_CWORD} -eq 1 ]]; then
+ COMPREPLY=($(compgen -W '-b -h -m' -- ${cur}))
+ elif [[ "${prev}" == "-b" ]]; then
+ COMPREPLY=($(compgen -W "$(for i in /usr/share/browser-config/*; do [ -f $i ] && echo ${i##*/}; done)" $cur))
+ elif [[ "${prev}" == "-m" ]]; then
+ COMPREPLY=($(compgen -W "same_window new_window new_tab new_browser" -- ${cur}))
+ if [[ ! "${COMPREPLY}" ]]; then
+ COMPREPLY=''
+ fi
+ else
+ unset COMPREPLY
+ fi
+ return 0
+}
+complete -F _browserconfig browser-config
+}
+
+have equery && {
+#
+# This function completes package names.
+#
+# usage: pkgname <mode> <current-directory>
+#
+# Where mode is one of:
+# -A Search all available packages (except for those in the overlays)
+# -I Only search the installed packages
+#
+# TODO: Look at breaking this function out and making it a "universal"
+# category/package name completion function.
+#
+_pkgname()
+{
+ local mode cur portdir
+ mode="$1"
+ cur="$2"
+ portdir=$(_portdir)
+ # Ignore '=' at the beginning of the current completion
+ [[ ${cur:1:1} == "=" ]] && cur=${cur:2}
+ [[ ${cur:0:1} == "=" ]] && cur=${cur:1}
+ case $mode in
+ -I)
+ # Complete either the category or the complete package name
+ if [[ $cur == */* ]]; then
+ COMPREPLY=($(cd /var/db/pkg; compgen -W "$(compgen -G "$cur*" )" -- $cur))
+ else
+ COMPREPLY=($(cd /var/db/pkg; compgen -W "$(compgen -G "$cur*" -S /)" -- $cur))
+ fi
+ # We may just have finished completing the category.
+ # Make sure there isn't anything more to complete now.
+ if [ ${#COMPREPLY[@]} == 1 ]; then
+ COMPREPLY=($(cd /var/db/pkg; compgen -W "$(compgen -G "$COMPREPLY*")" -- $cur))
+ fi
+ ;;
+ -A)
+ # Complete either the category or the complete package name
+ if [[ $cur == */* ]]; then
+ # Once the category has been completed, it's safe to use ${portdir}
+ # to continue completion.
+ COMPREPLY=($(cd ${portdir}; compgen -W "$(compgen -G "${cur}*")" -- "${cur}"))
+ # When we've completed most of the name, also display the version for
+ # possible completion.
+ if [[ ${#COMPREPLY[@]} -le 1 || ${cur:${#cur}-1:1} == "-" ]] && [[ ${cur} != */ ]]; then
+ # The portage cache is appropriate to complete specific versions from.
+ COMPREPLY=(${COMPREPLY[@]} $(cd ${portdir}/metadata/cache; compgen -W "$(compgen -G "${cur}*")" -- "${cur}"))
+ fi
+ else
+ # For completing categories, it's easiest to use the portage cache.
+ COMPREPLY=($(compgen -W "$(cd ${portdir}/metadata/cache; compgen -G "$cur*" -S /)" -- $cur))
+ # Are we done completing the category?
+ if [ ${#COMPREPLY[@]} == 1 ]; then
+ COMPREPLY=($(compgen -W "$(cd ${portdir}/metadata/cache; compgen -G "$COMPREPLY*")" -- $cur))
+ fi
+ fi
+ ;;
+ *)
+ # Somebody screwed up! :-)
+ ;;
+ esac
+ # 'equery' wants an '=' in front of specific package versions.
+ # Add it if there is only one selected package and it isn't there already.
+ [[ ${#COMPREPLY[@]} == 1 && ${COMP_WORDS[COMP_CWORD]:0:1} != "=" ]] && COMPREPLY=("="$COMPREPLY)
+}
+
+#
+# Bash completion for the Gentoo 'equery' command
+#
+_equery()
+{
+ local cur prev mode portdir i j
+ portdir=$(_portdir)
+ mode="GLOBAL"
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ # Find out what we're currently doing here.
+ j=0
+ for i in "${COMP_WORDS[@]}"; do
+ if [ $j -lt $COMP_CWORD ]; then
+ j=$((j + 1))
+ case $i in @(belongs|ch@(anges|eck)|dep@(ends|graph)|files|glsa|list|s@(ize|tats)|uses|which|hasuse))
+ mode=$i
+ ;;
+ esac
+ fi
+ done
+ # Now get to work.
+ case $mode in
+ GLOBAL)
+ # Complete commands and global options.
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "-q --quiet -C --nocolor -h --help -V --version" -- $cur))
+ ;;
+ *)
+ COMPREPLY=($(compgen -W "belongs changes check depends depgraph files glsa hasuse list size stats uses which" -- $cur))
+ ;;
+ esac
+ ;;
+ changes|glsa|stats)
+ # These commands have not been implemented in 'equery' yet ...
+ echo -n "# Not implemented! "
+ ;;
+ files)
+ # Only complete if the previous entry on the command line is not
+ # a package name.
+ if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]]; then
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "--timestamp --md5sum --type" -- $cur))
+ ;;
+ *)
+ # Only installed packages can have their files listed.
+ _pkgname -I $cur
+ ;;
+ esac
+ fi
+ ;;
+ list)
+ # Only complete if the previous entry on the command line is not
+ # a package name.
+ if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]]; then
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "-i --installed -I --exclude-installed -p --portage-tree -o --overlay-tree" -- $cur))
+ ;;
+ *)
+ # Complete on all package names.
+ _pkgname -A $cur
+ ;;
+ esac
+ fi
+ ;;
+ belongs)
+ # Only complete if the previous entry on the command line is not
+ # a file name.
+ if \
+ [[ \
+ ${prev} == ${mode} || \
+ ${prev:0:1} == "-" || \
+ ${COMP_WORDS[COMP_CWORD-2]} == "-c" || \
+ ${COMP_WORDS[COMP_CWORD-2]} == "--category" \
+ ]] && \
+ [[ \
+ ${prev} != "-c" && \
+ ${prev} != "--category" \
+ ]]
+ then
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "-c --category -e --earlyout" -- $cur))
+ ;;
+ *)
+ # Complete filenames. Function defined in /etc/bash_completion.
+ _filedir
+ ;;
+ esac
+ # Are we completing a category?
+ elif [[ ${prev} == "-c" || ${prev} == "--category" ]]; then
+ COMPREPLY=($(cd ${portdir}/metadata/cache; compgen -W "$(compgen -G '*')" -- $cur))
+ fi
+ ;;
+ uses|which)
+ # Only complete if the previous entry on the command line is not
+ # a package name.
+ if [[ ${prev} == ${mode} ]]; then
+ # Complete on all package names.
+ _pkgname -A $cur
+ fi
+ ;;
+ depgraph)
+ # Only complete if the previous entry on the command line is not
+ # a package name.
+ if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]]; then
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "-U --no-useflags -l --linear" -- $cur))
+ ;;
+ *)
+ # Complete on installed package names.
+ _pkgname -I $cur
+ ;;
+ esac
+ fi
+ ;;
+ depends)
+ # Only complete if the previous entry on the command line is not
+ # a package name.
+ if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]]; then
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "-a --all-packages -d --direct -D --indirect" -- $cur))
+ ;;
+ *)
+ case $prev in
+ -a|--all-packages)
+ # Complete on all package names.
+ _pkgname -A $cur
+ ;;
+ *)
+ # Complete on installed package names.
+ _pkgname -I $cur
+ ;;
+
+ esac
+ esac
+ fi
+ ;;
+ check)
+ # Only complete if the previous entry on the command line is not
+ # a package name.
+ if [[ ${prev} == ${mode} ]]; then
+ # Only installed packages can have their integrity verified.
+ _pkgname -I $cur
+ fi
+ ;;
+ size)
+ # Only complete if the previous entry on the command line is not
+ # a package name.
+ if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]]; then
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "-b --bytes" -- $cur))
+ ;;
+ *)
+ # Only installed packages can have their size calculated.
+ _pkgname -I $cur
+ ;;
+ esac
+ fi
+ ;;
+ hasuse)
+ # Only complete if the previous entry on the command line is not
+ # a package name.
+ if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]]; then
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "-i --installed -I --exclude-installed -p --portage-tree -o --overlay" -- $cur))
+ ;;
+ *)
+ local glob loc
+ glob=$(sed -n -e 's/^\([^ ]\+\) - .*$/\1/p' ${portdir}/profiles/use.desc)
+ loc=$(sed -n -e 's/^[^ ]\+:\([^ ]*\) - .*$/\1/p' ${portdir}/profiles/use.local.desc)
+ COMPREPLY=($(compgen -W "$glob $loc" -- $cur))
+ ;;
+ esac
+ fi
+ ;;
+ esac
+ return 0
+}
+complete -F _equery -o filenames equery
+}
+
+#
+# ekeyword completion
+#
+
+have ekeyword && {
+_ekeyword()
+{
+ local cur portdir archl_s archl_u archl_r archl_m arch
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ portdir=$(_portdir)
+
+ for arch in all $(< ${portdir}/profiles/arch.list) ; do
+ archl_m="${archl_m} -${arch}"
+ archl_u="${archl_u} ~${arch}"
+ archl_r="${archl_r} ^${arch}"
+ archl_s="${archl_s} ${arch}"
+ done
+
+ case $cur in
+ -*)
+ COMPREPLY=( $( compgen -W "${archl_m}" -- $cur ) )
+ ;;
+ ~*)
+ COMPREPLY=( $( compgen -W "${archl_u}" -- $cur ) )
+ ;;
+ ^*)
+ COMPREPLY=( $( compgen -W "${archl_r}" -- $cur ) )
+ ;;
+ *)
+ if [ ${COMP_CWORD} -eq 1 ] ; then
+ COMPREPLY=( $(compgen -W "${archl_s}" -- $cur ) )
+ else
+ COMPREPLY=( $( compgen -W "${archl_s}" -- $cur ) )
+ _filedir 'ebuild'
+ fi
+ ;;
+ esac
+}
+complete -F _ekeyword ekeyword
+}
+
+# vim: set ft=sh tw=80 sw=4 et :