[Bash-completion-devel] ./current r1326: Improved strace completion, undefined _command_offset() found.

Guillaume Rousse Guillaume.Rousse at inria.fr
Thu Feb 5 23:17:43 UTC 2009


Guillaume Rousse a écrit :
> Incidentally, I also found current implementation has troubles in some 
> scenarios. For instance, try this:
> [guillaume at oberkampf bash-completion]$ sudo rpm -q sed: -e expression 
> #1, char 5: unterminated `s' command

You can also try 'sudo vim <TAB>' or 'sudo chown <TAB>', nothing seems 
to work at all :)

Here is a more readable implementation of the core of the _command 
function, solving those issues. Caution, I used bash 3.0 regexp, instead 
of the uneasy to read '[ "${cspec#* -F }" != "$cspec" ]' conditional, 
making the code not compatible with bash 2.X (But I understood wa wanted 
to go this way anyway...).

I'm waiting feedback before commiting.

if [[ $COMP_CWORD -eq 0 ]]; then
		COMPREPLY=( $( compgen -c -- $cur ) )
	else
		# check completion definition for the command
		cspec=$( complete -p $cmd 2>/dev/null)
		if [ -n "$cspec" ]; then
			# set bash 3.1 compat flag for regexp
			shopt -s compat31
			if [[ $cspec =~ "-F ([a-z_-]+)" ]]; then
				# defined completion is a function
				# shift COMP_CWORD elements, and call it
				func=${BASH_REMATCH[1]}
				if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
					$func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" 
"${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
				else
					$func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}"
				fi
			else
				# defined completion is not a function
				# evaluate it directly
				cspec=${cspec#complete};
				cspec=${cspec%%$cmd};
				COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
			fi
		fi
	fi



More information about the Bash-completion-devel mailing list