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

[PATCH] cg-completion: improve options and command listing

From
Jonas Fonseca <fonseca@diku.dk>
Date
Dec 11, 2005, 19:09 UTC
Message-ID
<20051211190931.GF2960@diku.dk>
Complete help options and improve filtering for command name completion.
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
 The current filtering causes all sorts of garbage to be listed in the
 command listing.

commit f0535e9952f1cace89d03649e8238aca69a6df44 tree e05dfadb63bd92ead0dc29d326065b7a797e2109 parent 3c14cded46e110396127fc5b5e65883eb5cd60b9 author Jonas Fonseca <fonseca@diku.dk> Wed, 07 Dec 2005 20:58:50 +0100 committer Jonas Fonseca <fonseca@antimatter.localdomain> Wed, 07 Dec 2005 20:58:50 +0100

 contrib/cg-completion.bash |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/contrib/cg-completion.bash b/contrib/cg-completion.bash
index 428f320..20b758f 100644
--- a/contrib/cg-completion.bash
+++ b/contrib/cg-completion.bash
@@ -23,8 +23,7 @@ __cg_branches()
 
 __cg_cmdlist()
 {
-	(cg help && cg help tag && cg help branch && cg help admin) | grep --regexp "cg-[^ ]* " | sed 's/^.*\cg-\([^ ]*\) .*$/\1/' | grep -v COMMAND
-
+	(cg help && cg help tag && cg help branch && cg help admin) | sed -n 's/.*cg-\([^ ]*\) .*/\1/p' | sort -u
 }
 
 _cg ()
@@ -33,17 +32,17 @@ _cg ()
     cur=${COMP_WORDS[COMP_CWORD]}
     COMPREPLY=()
     if [ $COMP_CWORD -eq 1 ]; then
-	COMPREPLY=( $(compgen -W "$(__cg_cmdlist)" -- $cur) )
+	COMPREPLY=( $(compgen -W "$(__cg_cmdlist) -h --help --version" -- $cur) )
     else
 	local cmd=${COMP_WORDS[1]}
 	local prev=${COMP_WORDS[COMP_CWORD-1]}
-	local o_help="-h --help"
+	local o_help="-h --help --long-help"
 	local o_branch="-b --branch"
 	case $cmd in
 	    add)
 	    # cg-add [-N] [-r] file...
 	    # XXX here could generate list of files and dirs excluding .git
-	    opts="-N -r"
+	    opts="-N -r $o_help"
 	    COMPREPLY=( $(compgen -d -f -W "${opts}" -- $cur ) )
 	    ;;
 
@@ -58,18 +57,18 @@ _cg ()
 
 	    clean)
 	    # Usage: cg-clean [-d] [-D] [-q] [-x]
-	    opts="-d -D -q -x"
+	    opts="-d -D -q -x $o_help"
 	    COMPREPLY=( $(compgen -W "${opts}" -- $cur ) )
 	    ;;
 
 	    help)
-	    opts="-c"
+	    opts="-c $o_help"
 	    COMPREPLY=( $(compgen -W "$(__cg_cmdlist) ${opts}" -- $cur) )
 	    ;;
 
 	    push)
 	    # cg-push [BRANCH_NAME] [-t TAG]
-	    opts="-t" 
+	    opts="-t $o_help" 
 	    if [ "$prev" = "-t" ]; then 
 	        COMPREPLY=( $(compgen -W "$(__git_tags)" -- $cur) )
 	    else
@@ -79,7 +78,7 @@ _cg ()
 
 	    merge)
 	    # cg-merge [-c] [-b BASE_COMMIT] [BRANCH_NAME]
-	    opts="-c -b" 
+	    opts="-c -b $o_help" 
 	    if [ "$prev" = "-b" ]; then 
 	        COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
 	    else
@@ -89,7 +88,7 @@ _cg ()
 
 	    commit) 
             # cg-commit [-m MESSAGE]... [-C] [-e | -E] [-c COMMIT_ID] [FILE]
-	    opts="-m -C -e -E -c" 
+	    opts="-m -C -e -E -c $o_help" 
 	    if [ "$prev" = "-m" ]; then 
 		COMPREPLY="\"\""
 	    elif [ "$prev" = "-c" ]; then 
@@ -101,7 +100,7 @@ _cg ()
 
 	    diff)
             # cg-diff [-c] [-m] [-s] [-p] [-r FROM_ID[:TO_ID]] [FILE]...
-            opts="-c -m -s -p -r"
+            opts="-c -m -s -p -r $o_help"
 	    if [ "$prev" = "-r" ]; then 
             # TODO need some kinkiness to handle -r FROM:TO completion
 		COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
@@ -111,7 +110,7 @@ _cg ()
 	    ;;
 
 	    log)
-            opts="-c -f -r -d -m -s -u --summary"
+            opts="-c -f -r -d -m -s -u --summary $o_help"
 	    if [ "$prev" = "-r" ]; then 
             # TODO need some kinkiness to handle -r FROM:TO completion
 		COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
@@ -131,7 +130,7 @@ _cg ()
 	    ;;
 	    switch)
 	    # Usage: cg-switch [-f] [-n] [-r COMMIT_ID] BRANCH
-	    opts="-f -n -r"  # TODO -r 
+	    opts="-f -n -r $o_help"  # TODO -r 
 	    COMPREPLY=( $(compgen -W "${opts} $(__git_heads)" -- $cur) )
 	    ;;
 
-- 
Jonas Fonseca
Next: Ben Clifford
Message 1 of 5 in “cg-completion: improve options and command listing”
  1. cg-completion: improve options and command listingJonas Fonseca, Dec 11, 2005
  2. Ben CliffordDec 17, 2005
  3. Jonas FonsecaDec 18, 2005
  4. Ben CliffordDec 19, 2005
  5. Ben CliffordDec 20, 2005

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.