public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] updated emerge bash completion + question
@ 2001-12-13 12:34 Geert Bevin
  2001-12-13 21:13 ` Zach Forrest
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Bevin @ 2001-12-13 12:34 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 827 bytes --]

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.

-- 
Geert Bevin
the Leaf sprl/bvba
"Use what you need"           Pierre Theunisstraat 1/47
http://www.theleaf.be         1030 Brussels
gbevin@theleaf.be             Tel & Fax +32 2 241 19 98

[-- Attachment #2: emerge.completion --]
[-- Type: text/plain, Size: 1360 bytes --]

# 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] updated emerge bash completion + question
  2001-12-13 12:34 [gentoo-dev] updated emerge bash completion + question Geert Bevin
@ 2001-12-13 21:13 ` Zach Forrest
  2001-12-14 10:07   ` Geert Bevin
  0 siblings, 1 reply; 4+ messages in thread
From: Zach Forrest @ 2001-12-13 21:13 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 3048 bytes --]

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
> 


[-- Attachment #2: emerge.completion --]
[-- Type: text/plain, Size: 1747 bytes --]

# 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] updated emerge bash completion + question
  2001-12-13 21:13 ` Zach Forrest
@ 2001-12-14 10:07   ` Geert Bevin
  2001-12-14 18:37     ` Zach Forrest
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Bevin @ 2001-12-14 10:07 UTC (permalink / raw
  To: gentoo-dev

Well this works, but it doesn't use the bash normal file completion
command which imho is not implemented correctly. I don't think that
--usepkg should limit itself to the binary packages directory, the
completion that follows should be a standard bash file completion. If
you see how file completion on other commands has been implemented, then
you'll see that they suffer from the same problem (eg. chown chmod ....)
I think that the compgen implementation of -f is flawed, it doesn't
react any different than -d. I'll try to contact the bash author(s).

On Thu, 2001-12-13 at 22:13, Zach Forrest wrote:
> 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
the Leaf sprl/bvba
"Use what you need"           Pierre Theunisstraat 1/47
http://www.theleaf.be         1030 Brussels
gbevin@theleaf.be             Tel & Fax +32 2 241 19 98



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] updated emerge bash completion + question
  2001-12-14 10:07   ` Geert Bevin
@ 2001-12-14 18:37     ` Zach Forrest
  0 siblings, 0 replies; 4+ messages in thread
From: Zach Forrest @ 2001-12-14 18:37 UTC (permalink / raw
  To: gentoo-dev

I think you may be right.

Geert Bevin wrote:

> Well this works, but it doesn't use the bash normal file completion
> command which imho is not implemented correctly. I don't think that
> --usepkg should limit itself to the binary packages directory, the
> completion that follows should be a standard bash file completion. If
> you see how file completion on other commands has been implemented, then
> you'll see that they suffer from the same problem (eg. chown chmod ....)
> I think that the compgen implementation of -f is flawed, it doesn't
> react any different than -d. I'll try to contact the bash author(s).
> 
> On Thu, 2001-12-13 at 22:13, Zach Forrest wrote:
> 
>>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
>>




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-12-14 18:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-12-13 12:34 [gentoo-dev] updated emerge bash completion + question Geert Bevin
2001-12-13 21:13 ` Zach Forrest
2001-12-14 10:07   ` Geert Bevin
2001-12-14 18:37     ` Zach Forrest

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox