Re: [PATCH] completion: add option completion for most builtin commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Duy Nguyen <pclouds@xxxxxxxxx> writes:

> +__git_main_with_parseopt_helper='
> +	blame cat-file check-attr check-ignore
> +	check-mailmap checkout-index column count-objects fast-export
> +	hash-object index-pack interpret-trailers merge-file mktree
> +	pack-objects pack-refs prune prune-packed read-tree repack
> +	send-pack show-ref stripspace symbolic-ref update-index
> +	update-ref verify-commit verify-tag write-tree
> +'
> +__git_complete_command() {
> +	local command="$1"
> +	local completion_func="_git_${command//-/_}"
> +	if declare -f $completion_func >/dev/null 2>/dev/null; then
> +		$completion_func
> +	elif echo $__git_main_with_parseopt_helper | git grep -w "$command" >/dev/null; then

"git grep"???

I imagined that you'd keep an associative shell array (we are not
constrained by POSIX here) that can be used like so

	elif test -n "${__git_main_with_parseopt_helper[$command]}"; then

Of course, a more traditional way to write it without spawning grep
or pipe is

	case " $__git_main_with_parseopt_helper " in
	*" $command "*)
		... Yes, $command is on the list ...
		;;
	*)
		... No, $command is not on the list ...
		;;
	esac



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux