From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on finch.gentoo.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=DMARC_NONE,MAILING_LIST_MULTI, RDNS_DYNAMIC autolearn=no autolearn_force=no version=4.0.0 Received: from pd4mo3so.prod.shaw.ca (h24-71-223-13.cg.shawcable.net [24.71.223.13]) by chiba.3jane.net (Postfix) with ESMTP id BAF3B1513E for ; Thu, 13 Dec 2001 15:13:34 -0600 (CST) Received: from pd5mr2so.prod.shaw.ca (pd5mr2so-qfe3.prod.shaw.ca [10.0.141.233]) by l-daemon (iPlanet Messaging Server 5.0 Patch 2 (built Dec 14 2000)) with ESMTP id <0GOA00757WAOAJ@l-daemon> for gentoo-dev@gentoo.org; Thu, 13 Dec 2001 14:13:36 -0700 (MST) Received: from pn2ml8so (pn2ml8so-qfe0.prod.shaw.ca [10.0.121.152]) by l-daemon (iPlanet Messaging Server 5.1 (built May 7 2001)) with ESMTP id <0GOA006M6WAOPV@l-daemon> for gentoo-dev@gentoo.org; Thu, 13 Dec 2001 14:13:36 -0700 (MST) Received: from shaw.ca ([24.68.91.28]) by l-daemon (iPlanet Messaging Server 5.0 Patch 2 (built Dec 14 2000)) with ESMTP id <0GOA00L3VW3RCI@l-daemon> for gentoo-dev@gentoo.org; Thu, 13 Dec 2001 14:09:27 -0700 (MST) Date: Thu, 13 Dec 2001 13:13:09 -0800 From: Zach Forrest Subject: Re: [gentoo-dev] updated emerge bash completion + question To: gentoo-dev@gentoo.org Message-id: <3C1919E5.4010701@shaw.ca> MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_K04CmCL9qYvDueh2OISAxQ)" X-Accept-Language: en-us User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.6) Gecko/20011130 References: <1008246896.1016.10.camel@willow.theleaf.office> Sender: gentoo-dev-admin@gentoo.org Errors-To: gentoo-dev-admin@gentoo.org X-BeenThere: gentoo-dev@gentoo.org X-Mailman-Version: 2.0.6 Precedence: bulk Reply-To: gentoo-dev@gentoo.org List-Help: List-Post: List-Subscribe: , List-Id: Developer discussion list List-Unsubscribe: , List-Archive: X-Archives-Salt: 9441e2be-36f5-4afa-a28f-d7c65a2d0505 X-Archives-Hash: 13cc6b3647e0079d0d2416138e4acf51 This is a multi-part message in MIME format. --Boundary_(ID_K04CmCL9qYvDueh2OISAxQ) Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT This seems to work (see attachment). [DISCLAIMER: I make no claims that this is pretty.] Geert, I think the problem with filename completion when '--usepkg' is specified has to do with the suffix and glob flags when setting $setsma. I made a few other changes and was having the same problem (i.e. after the dirname was completed, it appended a "/" and added a space; interestingly, though, was that when I backspaced, it then completed on filenames properly). To get it working, I removed the '-S' flag and changed the glob pattern to "*/" (only when '--usepkg' is specified, of course). Maybe one of us should mail this addition to the bash_completion maintainer so it can be included in the main package. (He might also be able to clean it up a bit. If you'd like to send it in, feel free to point the finger at me for the hacks. ;-) ) Zach Geert Bevin wrote: > Hi all, > > here is a slightly updated emerge bash completion which also completes > the arguments now and adds 'update' and 'system' to the completions. > > I have one problem though. emerge --usepkg should complete on files. > Normally a command that completes on files is defined with 'complete -f > command'. The bash info says that the 'comspec' builtin which is used to > generate completion matches generates those matches in the same way as > 'complete', however when using 'comspec -f' the filename completion > stops after one path element and doesn't continue until a file has been > reached. Does someone know how to work around this? > > Geert. > > > > ------------------------------------------------------------------------ > > # Gentoo emerge completion. > # > _emerge() > { > local cur prev grepcmd sedcmd systemactions setsma setbig > > COMPREPLY=() > cur=${COMP_WORDS[COMP_CWORD]} > prev=${COMP_WORDS[COMP_CWORD-1]} > > if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then > COMPREPLY=( $( compgen -W '--pretend \ > --autoclean \ > --usepkg \ > --buildpkg' | grep ^$cur ) ) > elif [ "$prev" == "--usepkg" ]; then > COMPREPLY=( $( compgen -f $cur ) ) > else > cd /usr/portage > grepcmd="grep -E ^$cur.*" > sedcmd="sed -e /CVS/d \ > -e /BUGS-TODO/d \ > -e /ChangeLog.*/d \ > -e /header.txt/d \ > -e /skel.build/d \ > -e /distfiles/d \ > -e /eclass/d \ > -e /files/d \ > -e /incoming/d \ > -e /packages/d \ > -e /profiles/d \ > -e /scripts/d" > systemactions=$'\n'"system"$'\n'"upgrade" > setsma="`compgen -S '/' -G "*" | $sedcmd`"$systemactions > setbig="`compgen -G "*/*" | $sedcmd`"$systemactions > if [ $cur ]; then > if [ `echo $cur | grep '/'` ]; then > COMPREPLY=( $( echo "$setbig" | $grepcmd ) ) > else > if [ `echo "$setsma" | $grepcmd | grep '/' | wc -l` = 1 ]; then > COMPREPLY=( $( echo "$setbig" | $grepcmd ) ) > else > COMPREPLY=( $( echo "$setsma" | $grepcmd ) ) > fi > fi > else > COMPREPLY=( $( echo "$setsma" ) ) > fi > fi > > return 0 > } > complete -F _emerge emerge > --Boundary_(ID_K04CmCL9qYvDueh2OISAxQ) Content-type: text/plain; name=emerge.completion Content-transfer-encoding: 7BIT Content-disposition: inline; filename=emerge.completion # Gentoo emerge completion. # have emerge && _emerge() { local cur prev grepcmd sedcmd systemactions setsma setbig portagedir usepkg # This is where the packages are found unless '--usepkg' is specified. portagedir=/usr/portage COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--pretend \ --autoclean \ --usepkg \ --buildpkg' | grep ^$cur ) ) else if [ "$prev" == "--usepkg" ]; then if [ -e "${PKGDIR}" ]; then portagedir=${PKGDIR} else portagedir="/usr/portage/packages" fi usepkg="TRUE" COMPREPLY=( $( compgen -f $cur ) ) fi cd ${portagedir} grepcmd="grep -E ^$cur.*" sedcmd="sed -e /CVS/d \ -e /BUGS-TODO/d \ -e /ChangeLog.*/d \ -e /header.txt/d \ -e /skel.build/d \ -e /distfiles/d \ -e /eclass/d \ -e /files/d \ -e /incoming/d \ -e /packages/d \ -e /profiles/d \ -e /All/d \ -e /scripts/d" if [ "${usepkg}" ]; then setsma="`compgen -G "*/" | $sedcmd`" setbig="`compgen -G "*/*" | $sedcmd`" else systemactions=$'\n'"system"$'\n'"upgrade" setsma="`compgen -S '/' -G "*" | $sedcmd`"$systemactions setbig="`compgen -G "*/*" | $sedcmd`"$systemactions fi if [ $cur ]; then if [ `echo $cur | grep '/'` ]; then COMPREPLY=( $( echo "$setbig" | $grepcmd ) ) else if [ `echo "$setsma" | $grepcmd | grep '/' | wc -l` = 1 ]; then COMPREPLY=( $( echo "$setbig" | $grepcmd ) ) else COMPREPLY=( $( echo "$setsma" | $grepcmd ) ) fi fi else COMPREPLY=( $( echo "$setsma" ) ) fi fi return 0 } [ "$have" ] && complete -F _emerge emerge --Boundary_(ID_K04CmCL9qYvDueh2OISAxQ)--