view bash_completion @ 6:3021deef1599

Encoding related fixes * chomp encoding string * reformat else (seems someone hacked it in) * debug print encoding * do not use :utf8 binmode ("re-encode") on written file if the input is _already_ UTF-8
author Peter Gervai <grin@grin.hu>
date Thu, 16 Oct 2008 00:02:14 +0200
parents a84c32f131df
children
line wrap: on
line source

# bins completion for bash
#-*- mode: shell-script;-*-
_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