git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 22, 2018, 17:56 UTC
Message-ID
<xmqqtvt8kn92.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180322173553.GA20984@duynguyen.home>
Duy Nguyen <pclouds@gmail.com> writes:
Show 14 quoted lines
> +__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
Previous: Duy NguyenNext: Duy Nguyen
Message 6 of 18 in “completion: add option completion for most builtin commands”
  1. completion: add option completion for most builtin commandsNguyễn Thái Ngọc Duy, Mar 21, 2018
  2. Junio C HamanoMar 21, 2018
  3. Duy NguyenMar 22, 2018
  4. Junio C HamanoMar 22, 2018
  5. Duy NguyenMar 22, 2018
  6. Junio C HamanoMar 22, 2018
  7. Duy NguyenMar 22, 2018
  8. Duy NguyenMar 24, 2018
  9. 0/8 completion: add option completion for most builtin commandsNguyễn Thái Ngọc Duy, Mar 24, 2018
  10. 1/8 git.c: move cmd_struct declaration upNguyễn Thái Ngọc Duy, Mar 24, 2018
  11. 2/8 git.c: add hidden option --list-parseopt-builtinsNguyễn Thái Ngọc Duy, Mar 24, 2018
  12. 8/8 completion: use __gitcomp_builtin in _git_cherryNguyễn Thái Ngọc Duy, Mar 24, 2018
  13. 4/8 completion: factor out _git_xxx calling codeNguyễn Thái Ngọc Duy, Mar 24, 2018
  14. 7/8 completion: use __gitcomp_builtin in _git_ls_treeNguyễn Thái Ngọc Duy, Mar 24, 2018
  15. 3/8 completion: mention the oldest version we need to supportNguyễn Thái Ngọc Duy, Mar 24, 2018
  16. 6/8 completion: delete option-only completion commandsNguyễn Thái Ngọc Duy, Mar 24, 2018
  17. 5/8 completion: add --option completion for most builtin commandsNguyễn Thái Ngọc Duy, Mar 24, 2018
  18. Eric SunshineMar 25, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.