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

From: Jonas Fonseca <[email-masked]>
Date: Sun, 11 Dec 2005 20:09:31 +0100

Complete help options and improve filtering for command name completion.

Signed-off-by: Jonas Fonseca <[email-masked]>

---

 The current filtering causes all sorts of garbage to be listed in the
 command listing.

commit f0535e9952f1cace89d03649e8238aca69a6df44
tree e05dfadb63bd92ead0dc29d326065b7a797e2109
parent 3c14cded46e110396127fc5b5e65883eb5cd60b9
author Jonas Fonseca <[email-masked]> Wed, 07 Dec 2005 20:58:50 +0100
committer Jonas Fonseca <[email-masked]> 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