1 # Cogito 'cg' bash completion.
3 # Copyright (c) Ben Clifford, 2005
4 # Copyright (c) Paolo Giarrusso, 2005
6 # The master version is available at:
7 # http://www.hawaga.org.uk/gitcompletion.git
9 bashdefault
="-o bashdefault"
14 REVERTGLOB
=`shopt -p nullglob`
16 if [ -n ".git/branches/*" ] ; then
17 for i
in $
(echo .git
/branches
/*); do
18 echo ${i#.git/branches/}
26 (cg
help && cg
help tag
&& cg
help branch
&& cg
help admin
) |
grep --regexp "cg-[^ ]* " |
sed 's/^.*\cg-\([^ ]*\) .*$/\1/' |
grep -v COMMAND
33 cur
=${COMP_WORDS[COMP_CWORD]}
35 if [ $COMP_CWORD -eq 1 ]; then
36 COMPREPLY
=( $
(compgen
-W "$(__cg_cmdlist)" -- $cur) )
38 local cmd
=${COMP_WORDS[1]}
39 local prev
=${COMP_WORDS[COMP_CWORD-1]}
40 local o_help
="-h --help"
41 local o_branch
="-b --branch"
44 # cg-add [-N] [-r] file...
45 # XXX here could generate list of files and dirs excluding .git
47 COMPREPLY
=( $
(compgen
-d -f -W "${opts}" -- $cur ) )
51 # cg branch-add BRANCH_NAME LOCATION
52 # nothing special for NEWBRANCH, but LOCATION can
54 if [ "$COMP_CWORD" = "3" ]; then
55 COMPREPLY
=( $
(compgen
-W "$(__git_repo_urls)" -- $cur ) )
60 # Usage: cg-clean [-d] [-D] [-q] [-x]
62 COMPREPLY
=( $
(compgen
-W "${opts}" -- $cur ) )
67 COMPREPLY
=( $
(compgen
-W "$(__cg_cmdlist) ${opts}" -- $cur) )
71 # cg-push [BRANCH_NAME] [-t TAG]
73 if [ "$prev" = "-t" ]; then
74 COMPREPLY
=( $
(compgen
-W "$(__git_tags)" -- $cur) )
76 COMPREPLY
=( $
(compgen
-W "${opts} $(__cg_branches)" -- $cur) )
81 # cg-merge [-c] [-b BASE_COMMIT] [BRANCH_NAME]
83 if [ "$prev" = "-b" ]; then
84 COMPREPLY
=( $
(compgen
-W "$(__git_refs)" -- $cur) )
86 COMPREPLY
=( $
(compgen
-W "${opts} $(__git_refs)" -- $cur) )
91 # cg-commit [-m MESSAGE]... [-C] [-e | -E] [-c COMMIT_ID] [FILE]
93 if [ "$prev" = "-m" ]; then
95 elif [ "$prev" = "-c" ]; then
96 COMPREPLY
=( $
(compgen
-W "$(__git_refs)" -- $cur) )
98 COMPREPLY
=( $
(compgen
-f -W "${opts} " -- $cur) )
103 # cg-diff [-c] [-m] [-s] [-p] [-r FROM_ID[:TO_ID]] [FILE]...
104 opts
="-c -m -s -p -r"
105 if [ "$prev" = "-r" ]; then
106 # TODO need some kinkiness to handle -r FROM:TO completion
107 COMPREPLY
=( $
(compgen
-W "$(__git_refs)" -- $cur) )
109 COMPREPLY
=( $
(compgen
-f -W "${opts} " -- $cur) )
114 opts
="-c -f -r -d -m -s -u --summary"
115 if [ "$prev" = "-r" ]; then
116 # TODO need some kinkiness to handle -r FROM:TO completion
117 COMPREPLY
=( $
(compgen
-W "$(__git_refs)" -- $cur) )
118 elif [ "$prev" = "-d" ]; then
119 # TODO what are good completions if any?
120 COMPREPLY
=( "yesterday" )
121 elif [ "$prev" = "-u" ]; then
122 # useful when the authors/committers have accounts on localhost?
123 COMPREPLY
=( $
(compgen
-u -- $cur) )
125 COMPREPLY
=( $
(compgen
-f -W "${opts} " -- $cur) )
133 # Usage: cg-switch [-f] [-n] [-r COMMIT_ID] BRANCH
134 opts
="-f -n -r" # TODO -r
135 COMPREPLY
=( $
(compgen
-W "${opts} $(__git_heads)" -- $cur) )
140 COMPREPLY
=( $
(compgen
$default -W "${o_help}" -f -- $cur) )
146 complete
$default -F _cg cg
149 # These are commands still TODO:
151 # cg-clone Clone a remote GIT repository.
152 # cg-export Exports a particular revision from a GIT repository.
153 # cg-fetch Fetch changes from a remote branch to the local GIT repository.
154 # cg-init Initialize a GIT repository.
155 # cg-mkpatch Make a patch from one or several commits.
156 # cg-object-id Get SHA1 ID of commit or tree associated with given ID or HEAD.
157 # cg-patch Apply a diff generated by cg-diff.
158 # cg-reset Resets the state of the working tree.
159 # cg-restore Restore files in the working tree to state at the given/last commit.
160 # cg-rm Remove files from a GIT repository.
161 # cg-seek Seek the working tree to a given commit.
162 # cg-status Show status of your working tree.
163 # cg-update Pull and merge changes from a branch to the local repository.
166 # vi: set ft=sh sw=4: