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

Re: [PATCH] bash completion: Add completion for 'git help'

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 25, 2008, 20:40 UTC
Message-ID
<20080725204051.GB23202@spearce.org>
In-Reply-To
<1216858043-53646-1-git-send-email-lee.marlow@gmail.com>
Lee Marlow <lee.marlow@gmail.com> wrote:
Show 10 quoted lines
> Renamed cached __git_commandlist to __git_porcelain_commandlist
> and added __git_all_commandlist that only filters out *--* helpers.
> Completions for 'git help' will use the __git_all_commandlist, while
> __git_porcelain_commandlist is used for git command completion.
> Users who actually read man pages may want to see help for plumbing
> commands.
> 
> Options added: --all --info --man --web
> 
> Signed-off-by: Lee Marlow <lee.marlow@gmail.com>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
> This version fixes a small error in the __git_all_commands
...
Show 100 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 2edb341..f3bdea4 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -349,10 +349,10 @@ __git_complete_revlist ()
>  	esac
>  }
>  
> -__git_commands ()
> +__git_all_commands ()
>  {
> -	if [ -n "$__git_commandlist" ]; then
> -		echo "$__git_commandlist"
> +	if [ -n "$__git_all_commandlist" ]; then
> +		echo "$__git_all_commandlist"
>  		return
>  	fi
>  	local i IFS=" "$'\n'
> @@ -360,6 +360,24 @@ __git_commands ()
>  	do
>  		case $i in
>  		*--*)             : helper pattern;;
> +		*) echo $i;;
> +		esac
> +	done
> +}
> +__git_all_commandlist=
> +__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
> +
> +__git_porcelain_commands ()
> +{
> +	if [ -n "$__git_porcelain_commandlist" ]; then
> +		echo "$__git_porcelain_commandlist"
> +		return
> +	fi
> +	local i IFS=" "$'\n'
> +	for i in "help" $(__git_all_commands)
> +	do
> +		case $i in
> +		*--*)             : helper pattern;;
>  		applymbox)        : ask gittus;;
>  		applypatch)       : ask gittus;;
>  		archimport)       : import;;
> @@ -427,8 +445,8 @@ __git_commands ()
>  		esac
>  	done
>  }
> -__git_commandlist=
> -__git_commandlist="$(__git_commands 2>/dev/null)"
> +__git_porcelain_commandlist=
> +__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
>  
>  __git_aliases ()
>  {
> @@ -767,6 +785,18 @@ _git_gc ()
>  	COMPREPLY=()
>  }
>  
> +_git_help ()
> +{
> +	local cur="${COMP_WORDS[COMP_CWORD]}"
> +	case "$cur" in
> +	--*)
> +		__gitcomp "--all --info --man --web"
> +		return
> +		;;
> +	esac
> +	__gitcomp "$(__git_all_commands)"
> +}
> +
>  _git_ls_remote ()
>  {
>  	__gitcomp "$(__git_remotes)"
> @@ -1369,7 +1399,8 @@ _git ()
>  		case "$i" in
>  		--git-dir=*) __git_dir="${i#--git-dir=}" ;;
>  		--bare)      __git_dir="." ;;
> -		--version|--help|-p|--paginate) ;;
> +		--version|-p|--paginate) ;;
> +		--help) command="help"; break ;;
>  		*) command="$i"; break ;;
>  		esac
>  		c=$((++c))
> @@ -1389,7 +1420,7 @@ _git ()
>  			--help
>  			"
>  			;;
> -		*)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
> +		*)     __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
>  		esac
>  		return
>  	fi
> @@ -1414,6 +1445,7 @@ _git ()
>  	fetch)       _git_fetch ;;
>  	format-patch) _git_format_patch ;;
>  	gc)          _git_gc ;;
> +	help)        _git_help ;;
>  	log)         _git_log ;;
>  	ls-remote)   _git_ls_remote ;;
>  	ls-tree)     _git_ls_tree ;;
-- 
Shawn.
Previous: Lee MarlowNext: Junio C Hamano
Message 3 of 15 in “bash completion: Add completion for 'git help'”
  1. bash completion: Add completion for 'git help'Lee Marlow, Jul 23, 2008
  2. bash completion: Add completion for 'git help'Lee Marlow, Jul 24, 2008
  3. Shawn O. PearceJul 25, 2008
  4. Junio C HamanoJul 25, 2008
  5. fetch refspec foo/* matches foo*Jeff King, Jul 26, 2008
  6. Jeff KingJul 26, 2008
  7. Johannes SchindelinJul 26, 2008
  8. Jeff KingJul 28, 2008
  9. Junio C HamanoJul 28, 2008
  10. Jeff KingJul 28, 2008
  11. Junio C HamanoJul 27, 2008
  12. make sure parsed wildcard refspec ends with slashJunio C Hamano, Jul 27, 2008
  13. Daniel BarkalowJul 27, 2008
  14. Jeff KingJul 28, 2008
  15. bash completion: Add completion for 'git help'Lee Marlow, Jul 24, 2008

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.