[Bins] bash completion for bins

Guillaume Rousse rousse at ccr.jussieu.fr
Sun Feb 15 13:02:01 GMT 2004


The following script provides bash-completion for bins. Can you please 
integrate it into bins CVS ?
-- 
If a program actually fits in memory and has enough disk space, it is 
guaranteed to crash.
	-- Murphy's Computer Laws n°5
-------------- next part --------------
# bins completion
#
_bins()
{
	local cur prev tempdir

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

	case "$prev" in
		-f)
			_filedir
			return 0
			;;
		-o)
			COMPREPLY=( $( compgen -W 'scaled copied custom' -- $cur ) )
			return 0
			;;
		-c)
			conffile=$HOME/.bins/binsrc
			for (( i=1; i < COMP_CWORD; i++ )); do
				if [[ "${COMP_WORDS[i]}" == -f ]]; then
					conffile=${COMP_WORDS[i+1]}
					break
				fi
			done
			COMPREPLY=( \
				$( awk -F'"' '/<colors style="/ {print $2}' $conffile | grep "^$cur" ) \
				$( awk -F"'" "/<colors style='/ {print $2}" $conffile | grep "^$cur" ) \
				)
			return 0
			;;
		-t)
			_filedir -d
			return 0
			;;
		-r)
			COMPREPLY=( $( compgen -W 'dirs pictures dirs,pictures' -- $cur ) )
			return 0
			;;
		-s)
			tempdir=/usr/share/bins
			for (( i=1; i < COMP_CWORD; i++ )); do
				if [[ "${COMP_WORDS[i]}" == -t ]]; then
					tempdir=${COMP_WORDS[i+1]}
					break
				fi
			done
			COMPREPLY=( $( find $tempdir -type d -maxdepth 1 -name templates.* | \
				sed -e "s|$tempdir/templates.||" | grep "^$cur" ) )
			return 0
			;;
	esac

	if [[ "$cur" == -* ]]; then
		COMPREPLY=( $( compgen -W '-f -o -d -c -s -t -p -r -e -i -n -v -h' -- $cur ) )
	else
		_filedir -d
	fi

}
complete -F _bins bins


More information about the Bins mailing list