File: cg-compl

package info (click to toggle)
git-completion 0%2B20060817-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 84 kB
  • ctags: 1
  • sloc: makefile: 30
file content (175 lines) | stat: -rw-r--r-- 5,049 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Cogito 'cg' bash completion.
#
# Copyright (c) Ben Clifford, 2005
# Copyright (c) Paolo Giarrusso, 2005
#
# The master version is available at:
#	http://www.hawaga.org.uk/gitcompletion.git

bashdefault="-o bashdefault"
default="-o default"

__cg_branches()
{
    REVERTGLOB=`shopt -p nullglob`
    shopt -s nullglob
    if [ -n ".git/branches/*" ] ; then
        for i in $(echo .git/branches/*); do
            echo ${i#.git/branches/}
        done
    fi
    $REVERTGLOB
}

__cg_cmdlist()
{
	(cg help && cg help tag && cg help branch && cg help admin) | sed -n 's/.*cg-\([^ ]*\) .*/\1/p' | sort -u
}

_cg ()
{
    local cur cmd opts
    cur=${COMP_WORDS[COMP_CWORD]}
    COMPREPLY=()
    if [ $COMP_CWORD -eq 1 ]; then
	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 --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 $o_help"
	    COMPREPLY=( $(compgen -d -f -W "${opts}" -- $cur ) )
	    ;;

	    branch-add)
	    # cg branch-add BRANCH_NAME LOCATION
            # nothing special for NEWBRANCH, but LOCATION can
	    # be completed
            if [ "$COMP_CWORD" = "3" ]; then 
		COMPREPLY=( $(compgen -W "$(__git_repo_urls)" -- $cur ) )
	    fi
	    ;;

	    clean)
	    # Usage: cg-clean [-d] [-D] [-q] [-x]
	    opts="-d -D -q -x $o_help"
	    COMPREPLY=( $(compgen -W "${opts}" -- $cur ) )
	    ;;

	    fetch)
	    COMPREPLY=( $(compgen -W "${opts} $(__cg_branches)" -- $cur) )
	    ;;

	    help)
	    opts="-c $o_help"
	    COMPREPLY=( $(compgen -W "$(__cg_cmdlist) ${opts}" -- $cur) )
	    ;;

	    pull)
	    # cg-push [BRANCH_NAME] [-t TAG]
	    COMPREPLY=( $(compgen -W "${opts} $(__cg_branches)" -- $cur) )
	    ;;

	    push)
	    # cg-push [BRANCH_NAME] [-t TAG]
	    opts="-t $o_help" 
	    if [ "$prev" = "-t" ]; then 
	        COMPREPLY=( $(compgen -W "$(__git_tags)" -- $cur) )
	    else
	        COMPREPLY=( $(compgen -W "${opts} $(__cg_branches)" -- $cur) )
	    fi
	    ;;

	    merge)
	    # cg-merge [-c] [-b BASE_COMMIT] [BRANCH_NAME]
	    opts="-c -b $o_help" 
	    if [ "$prev" = "-b" ]; then 
	        COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
	    else
	        COMPREPLY=( $(compgen -W "${opts} $(__git_refs)" -- $cur) )
	    fi
	    ;;

	    commit) 
            # cg-commit [-m MESSAGE]... [-C] [-e | -E] [-c COMMIT_ID] [FILE]
	    opts="-m -C -e -E -c $o_help" 
	    if [ "$prev" = "-m" ]; then 
		COMPREPLY="\"\""
	    elif [ "$prev" = "-c" ]; then 
		COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
	    else
		COMPREPLY=( $(compgen -f -W "${opts} " -- $cur) )
	    fi
	    ;;

	    diff)
            # cg-diff [-c] [-m] [-s] [-p] [-r FROM_ID[:TO_ID]] [FILE]...
            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) )
	    else
		COMPREPLY=( $(compgen -f -W "${opts} " -- $cur) )
	    fi
	    ;;

	    log)
            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) )
	    elif [ "$prev" = "-d" ]; then 
            # TODO what are good completions if any?
		COMPREPLY=( "yesterday" )
	    elif [ "$prev" = "-u" ]; then 
            # useful when the authors/committers have accounts on localhost?
		COMPREPLY=( $(compgen -u -- $cur) )
	    else
		COMPREPLY=( $(compgen -f -W "${opts} " -- $cur) )
	    fi
	    ;;
	    version)
            # no options
            COMPREPLY=()
	    ;;
	    switch)
	    # Usage: cg-switch [-f] [-n] [-r COMMIT_ID] BRANCH
	    opts="-f -n -r $o_help"  # TODO -r 
	    COMPREPLY=( $(compgen -W "${opts} $(__git_heads)" -- $cur) )
	    ;;


	    *)
	    COMPREPLY=( $(compgen $default -W "${o_help}" -f -- $cur) )
	    ;;
	esac
    fi
}

complete $default -F _cg cg 


# These are commands still TODO:

#	cg-clone           Clone a remote GIT repository.
#	cg-export          Exports a particular revision from a GIT repository.
#	cg-fetch           Fetch changes from a remote branch to the local GIT repository.
#	cg-init            Initialize a GIT repository.
#	cg-mkpatch         Make a patch from one or several commits.
#	cg-object-id       Get SHA1 ID of commit or tree associated with given ID or HEAD.
#	cg-patch           Apply a diff generated by cg-diff.
#	cg-reset           Resets the state of the working tree.
#	cg-restore         Restore files in the working tree to state at the given/last commit.
#	cg-rm              Remove files from a GIT repository.
#	cg-seek            Seek the working tree to a given commit.
#	cg-status          Show status of your working tree.
#	cg-update          Pull and merge changes from a branch to the local repository.


# vi: set ft=sh sw=4: