Skip to contentSkip to conversation

cg-completion: improve options and command listing

PATCH In review Jonas Fonseca 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cg-completion: improve options and command listing

Complete help options and improve filtering for command name completion.

---

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 protected]> Wed, 07 Dec 2005 20:58:50 +0100 committer Jonas Fonseca <[email protected]> Wed, 07 Dec 2005 20:58:50 +0100

 contrib/cg-completion.bash |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
contrib/cg-completion.bash +12 -13
index 428f320..20b758f 100644
@@ -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) )
 	    ;;
 
Signature · 1 line
Jonas Fonseca
#1 lore raw
Quoted 5 lines · Jonas Fonseca

Complete help options and improve filtering for command name completion.

Hi. I've applied this patch to the dev branch cg-compl in my gitcompletion repo.

I'm interested by what you mean by 'all sorts of garbage' - it seems ok on my machine.

Ben

Quoted 11 lines

---

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 protected]> Wed, 07 Dec 2005 20:58:50 +0100 committer Jonas Fonseca <[email protected]> Wed, 07 Dec 2005 20:58:50 +0100

Signature · 4 lines
Ben • ベン • Бэн • 벤 • 班明
http://www.hawaga.org.uk/ben/
My email is high latency but best way to contact me. Alternatively,  
SMS number(s) at above URL.
#2 lore raw

Ben Clifford <[email protected]> wrote Sun, Dec 18, 2005:

Quoted 6 lines · Jonas Fonseca
Quoted 4 lines

Complete help options and improve filtering for command name completion.

Quoted 8 lines
Quoted 2 lines

Hi. I've applied this patch to the dev branch cg-compl in my gitcompletion repo.

I'm interested by what you mean by 'all sorts of garbage' - it seems ok on my machine.

~/src/cogito/cogito > __cg_cmdlist | head

        cg-add             Add files to the GIT repository.
        cg-clean           Clean unknown files from the working tree.
        cg-clone           Clone a remote GIT repository.
        cg-commit          Commit into a GIT repository.
        cg-diff            Make a diff between two GIT trees.
        cg-export          Exports a particular revision from a GIT repository.
        cg-fetch           Fetch changes from a remote branch to the local GIT repository.
        cg-help            Show help for Cogito commands.
        cg-init            Initialize a GIT repository.
        cg-log             Make a log of changes in a GIT branch.

Else I was thinking of maybe adding --list parameter to cg-help to have it list all known commands.

Signature · 1 line
Jonas Fonseca
#3 lore raw
Quoted 8 lines · Jonas Fonseca
Quoted 3 lines

I'm interested by what you mean by 'all sorts of garbage' - it seems ok on my machine.

~/src/cogito/cogito > __cg_cmdlist | head

        cg-add             Add files to the GIT repository.
        cg-clean           Clean unknown files from the working tree.
        cg-clone           Clone a remote GIT repository.

I definitely don't get that here. Bleugh!

Quoted 3 lines

Else I was thinking of maybe adding --list parameter to cg-help to have
it list all known commands.

One thing that seemed kinda neat that I saw somewhere (perhaps in darcs?) is that it will tab complete only commands that would make sense in the present location (so cg <tab> would perhaps only bring up 'init' and 'help' in a non-git directory) - that would be rather more invasive to implement, I expect.

Another thing that has been mooted is autogenerating the completion code based on USAGE info - I've had a hack about in the past with that (its in the autogen branch in the gitcompletion repo on hawaga.org.uk) but then I reached the point where it seemed too icky for my tastes...

Signature · 4 lines
Ben • ベン • Бэн • 벤 • 班明
http://www.hawaga.org.uk/ben/
My email is high latency but best way to contact me. Alternatively,  
SMS number(s) at above URL.
#4 lore raw
In reply to Jonas Fonseca
Quoted 2 lines · Jonas Fonseca

Else I was thinking of maybe adding --list parameter to cg-help to have it list all known commands.

yeah, that would be nice.

Signature · 1 line
http://www.hawaga.org.uk/ben/