Skip to contentSkip to conversation

bash-completion for bitbake

DISCUSSION Filippo Basso 3 participants 5 messages Dec 12, 2007 – Dec 14, 2007

lore
Share & tools
lore
#0 lore raw

For everybody interested,
I'm attaching here a small bash-completion script that I'm using.
(other scripts will be sent soon)
if somebody will make any improvements, plz send to me too...

(maybe somebody else already did... but I haven't found, can be useful to put it in the website? you OE guys see, if there is no way to put there, I'll upload in a personal page about my work on OE...? suggestions well accepted)

thanx,
phy

P.S. of course, if you want to see all the recipies, it will take long, but if you specify the first 1 or 2 characters, it's much faster!

#
# "bitbake autocompletion description"
#
# CREATED: Filippo Basso <[email protected]> (12-DEC-2007)
# MODIFIED:
#
# Use:
# - simply put it into your /etc/bash_completion.d/ directory... # For help enhancing this script, see also:
# - http://www.debian-administration.org/articles/317
# - http://www.gnu.org/software/bash/manual/bashref.html#SEC112
#

_bitbake()

{
	local cur conns prev options options1 i j A recipefile
	COMPREPLY=()

	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	options="--help --version --buildfile= --continue --force --interactive --cmd= --read= --verbose --debug --dry-run --parse-only --disable-psyco --show-versions --environment --graphviz --ignore-deps= --log-domains= --profile"
	options1="-h -b -k -f -i -c -r -v -D -n -p -d -s -e -g -I -l -P"

	# ------- Sanity checks -------
	if [[ ${BBPATH} == "" ]]
	then
		echo
		echo "variable \$BBPATH not set, please set it before launching bitbake... thanx"
		return 1
	fi

	# ------- Options completion -------
	if [[ ${cur} == -* ]]
	then
    		if [[ ${cur} == --* ]]
		then
			COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
			return 0
		else
       			COMPREPLY=( $(compgen -W "${options1}" -- ${cur}) )
        		return 0
		fi
	fi

	# ------- Recipe list autocompletion -------
	for i in `echo $BBPATH | sed s/:/\ /g` ;
	do
	        if [[ $i != "." ]]
	        then
	                for j in `echo $i/packages/*/${cur}*.bb` ;
	                do
				if [[ -f $j ]]
				then
	                        	recipefile=`basename $j`
	                        	conns="$conns \\n ${recipefile%%_*.bb}"
				fi
	                done
	        fi
	done
    	COMPREPLY=( $(compgen -W "${conns}" -- ${cur}) )
	return 0

}
complete -F _bitbake bitbake

#1 lore raw
Quoted 5 lines · Filippo Basso

For everybody interested,
I'm attaching here a small bash-completion script that I'm using.
(other scripts will be sent soon)
if somebody will make any improvements, plz send to me too...

Quoted 7 lines

(maybe somebody else already did... but I haven't found, can be useful to put it in the website? you OE guys see, if there is no way to put there, I'll upload in a personal page about my work on OE...? suggestions well accepted)

thanx,
phy

Very nice! Can't we put this somewhere in OE/contrib?
I think it would be nice if bitbake could provide this information itself, maybe making use of the cache. This would also allow to add versions and virtual providers to the autocompletion.

regards
Philipp

#2 lore raw

Am 13.12.2007 um 09:04 schrieb pHilipp Zabel:

Quoted 11 lines · Filippo Basso
Quoted 10 lines

For everybody interested,
I'm attaching here a small bash-completion script that I'm using.
(other scripts will be sent soon)
if somebody will make any improvements, plz send to me too...

(maybe somebody else already did... but I haven't found, can be useful to put it in the website? you OE guys see, if there is no way to put there, I'll upload in a personal page about my work on OE...? suggestions well accepted)

Quoted 7 lines
Quoted 2 lines

thanx,
phy

Very nice! Can't we put this somewhere in OE/contrib?
I think it would be nice if bitbake could provide this information itself, maybe making use of the cache. This would also allow to add versions and virtual providers to the autocompletion.

Hey Filippo,
what license is the completion under? I would like to put it into
http://svn.berlios.de/viewcvs/bitbake/trunk/bitbake/contrib/

z.

#3 lore raw

Holger Freyther ha scritto:

Quoted 26 lines

Am 13.12.2007 um 09:04 schrieb pHilipp Zabel:

Quoted 13 lines · Filippo Basso
Quoted 12 lines

For everybody interested,
I'm attaching here a small bash-completion script that I'm using.
(other scripts will be sent soon)
if somebody will make any improvements, plz send to me too...

(maybe somebody else already did... but I haven't found, can be useful
to put it in the website? you OE guys see, if there is no way to put there, I'll upload in a personal page about my work on OE...? suggestions well accepted)

Quoted 9 lines
Quoted 3 lines

thanx,
phy

Very nice! Can't we put this somewhere in OE/contrib?
I think it would be nice if bitbake could provide this information itself,
maybe making use of the cache. This would also allow to add versions and virtual providers to the autocompletion.

Quoted 6 lines

Hey Filippo,
what license is the completion under? I would like to put it into
http://svn.berlios.de/viewcvs/bitbake/trunk/bitbake/contrib/

z.

Thank you for the proposal!
I think that the bitbake license is perfect, GNU GPL v2 or any other
later version.
anyway:
* attached is a newer version that try to autocomplete the "-c" option with the more common tasks (it's not possible to do listtasks, as the package will be typed later...)(I hope I've listed all the more common ones)
* about use of the cache, I tried to use also the autocompletion one (it reduce of ~30% the time), but I then removed as it's not so accurate, expecially because autocompletion is useful for developers, where .bb files can change a lot... can bitbake cache be better in this regard?

phy

#
# "bitbake autocompletion description"
#
# LICENSE: GNU GPLv2 or any later version
# CREATED: Filippo Basso <[email protected]> (12-DEC-2007)
# MODIFIED:
#
# Use:
# - simply put it into your /etc/bash_completion.d/ directory... # For help enhancing this script, see also:
# - http://www.debian-administration.org/articles/317
# - http://www.gnu.org/software/bash/manual/bashref.html#SEC112
#

_bitbake()

{
	local cur conns prev options options1 i j A recipefile
	COMPREPLY=()

	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	options="--help --version --buildfile= --continue --force --interactive --cmd= --read= --verbose --debug --dry-run --parse-only --disable-psyco --show-versions --environment --graphviz --ignore-deps= --log-domains= --profile"
	options1="-h -b -k -f -i -c -r -v -D -n -p -d -s -e -g -I -l -P"
	commands="fetchall listtasks rebuild compile build populate_staging mrproper fetch configure clean package unpack install package_write distribute_sources showdata qa_configure qa_staging patch devshell package_write_deb package_deb_install buildall"

	# ------- Sanity checks -------
	if [[ ${BBPATH} == "" ]]
	then
		echo
		echo "variable \$BBPATH not set, please set it before launching bitbake... thanx"
		return 1
	fi

	# ------- Options completion -------
	if [[ ${prev} == "-c" ]]
	then
		COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
		return 0
	fi

	if [[ ${cur} == -* ]]
	then
    		if [[ ${cur} == --* ]]
		then
			COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
			return 0
		else
       			COMPREPLY=( $(compgen -W "${options1}" -- ${cur}) )
        		return 0
		fi
	fi

	# ------- Recipe list autocompletion -------
	for i in `echo $BBPATH | sed s/:/\ /g` ;
	do
		for j in `echo $i/packages/*/${cur}*.bb` ;
	        do
			if [[ -f $j ]]
			then
	                       	recipefile=`basename $j`
	                       	conns="$conns \\n ${recipefile%%_*.bb}"
			fi
	        done
	done
    	COMPREPLY=( $(compgen -W "${conns}" -- ${cur}) )
	return 0

}
complete -F _bitbake bitbake

#4 lore raw

last version of the script,
works also with packages with no "_" in the recipe filename, bug
found/fixed this morning.
phy

#
# "bitbake autocompletion description"
#
# LICENSE: GNU GPLv2 or any later version
# CREATED: Filippo Basso <[email protected]> (12-DEC-2007)
# MODIFIED:
#
# Use:
# - simply put it into your /etc/bash_completion.d/ directory... # For help enhancing this script, see also:
# - http://www.debian-administration.org/articles/317
# - http://www.gnu.org/software/bash/manual/bashref.html#SEC112
#

_bitbake()

{
	local cur conns prev options options1 i j A recipefile
	COMPREPLY=()

	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	options="--help --version --buildfile= --continue --force --interactive --cmd= --read= --verbose --debug --dry-run --parse-only --disable-psyco --show-versions --environment --graphviz --ignore-deps= --log-domains= --profile"
	options1="-h -b -k -f -i -c -r -v -D -n -p -d -s -e -g -I -l -P"
	commands="fetchall listtasks rebuild compile build populate_staging mrproper fetch configure clean package unpack install package_write distribute_sources showdata qa_configure qa_staging patch devshell package_write_deb package_deb_install buildall"

	# ------- Sanity checks -------
	if [[ ${BBPATH} == "" ]]
	then
		echo
		echo "variable \$BBPATH not set, please set it before launching bitbake... thanx"
		return 1
	fi

	# ------- Options completion -------
	if [[ ${prev} == "-c" ]]
	then
		COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
		return 0
	fi

	if [[ ${cur} == -* ]]
	then
    		if [[ ${cur} == --* ]]
		then
			COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
			return 0
		else
       			COMPREPLY=( $(compgen -W "${options1}" -- ${cur}) )
        		return 0
		fi
	fi

	# ------- Recipe list autocompletion -------
	for i in `echo $BBPATH | sed s/:/\ /g` ;
	do
		for j in `echo $i/packages/*/${cur}*.bb` ;
	        do
			if [[ -f $j ]]
			then
	                       	recipefile=`basename $j`
				recipefile=${recipefile%%_*.bb}
				recipefile=${recipefile%%.bb}
	                       	conns="$conns ${recipefile}"
			fi
	        done
	done
    	COMPREPLY=( $(compgen -W "${conns}" -- ${cur}) )
	return 0

}
complete -F _bitbake bitbake