cogito: understand permissions written as "100755"
[cogito.git] / contrib / cg-completion.bash
blob428f320f9d4b52fc5a762d0fff5186a27758a269
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"
10 default="-o default"
12 __cg_branches()
14 REVERTGLOB=`shopt -p nullglob`
15 shopt -s nullglob
16 if [ -n ".git/branches/*" ] ; then
17 for i in $(echo .git/branches/*); do
18 echo ${i#.git/branches/}
19 done
21 $REVERTGLOB
24 __cg_cmdlist()
26 (cg help && cg help tag && cg help branch && cg help admin) | grep --regexp "cg-[^ ]* " | sed 's/^.*\cg-\([^ ]*\) .*$/\1/' | grep -v COMMAND
30 _cg ()
32 local cur cmd opts
33 cur=${COMP_WORDS[COMP_CWORD]}
34 COMPREPLY=()
35 if [ $COMP_CWORD -eq 1 ]; then
36 COMPREPLY=( $(compgen -W "$(__cg_cmdlist)" -- $cur) )
37 else
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"
42 case $cmd in
43 add)
44 # cg-add [-N] [-r] file...
45 # XXX here could generate list of files and dirs excluding .git
46 opts="-N -r"
47 COMPREPLY=( $(compgen -d -f -W "${opts}" -- $cur ) )
50 branch-add)
51 # cg branch-add BRANCH_NAME LOCATION
52 # nothing special for NEWBRANCH, but LOCATION can
53 # be completed
54 if [ "$COMP_CWORD" = "3" ]; then
55 COMPREPLY=( $(compgen -W "$(__git_repo_urls)" -- $cur ) )
59 clean)
60 # Usage: cg-clean [-d] [-D] [-q] [-x]
61 opts="-d -D -q -x"
62 COMPREPLY=( $(compgen -W "${opts}" -- $cur ) )
65 help)
66 opts="-c"
67 COMPREPLY=( $(compgen -W "$(__cg_cmdlist) ${opts}" -- $cur) )
70 push)
71 # cg-push [BRANCH_NAME] [-t TAG]
72 opts="-t"
73 if [ "$prev" = "-t" ]; then
74 COMPREPLY=( $(compgen -W "$(__git_tags)" -- $cur) )
75 else
76 COMPREPLY=( $(compgen -W "${opts} $(__cg_branches)" -- $cur) )
80 merge)
81 # cg-merge [-c] [-b BASE_COMMIT] [BRANCH_NAME]
82 opts="-c -b"
83 if [ "$prev" = "-b" ]; then
84 COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
85 else
86 COMPREPLY=( $(compgen -W "${opts} $(__git_refs)" -- $cur) )
90 commit)
91 # cg-commit [-m MESSAGE]... [-C] [-e | -E] [-c COMMIT_ID] [FILE]
92 opts="-m -C -e -E -c"
93 if [ "$prev" = "-m" ]; then
94 COMPREPLY="\"\""
95 elif [ "$prev" = "-c" ]; then
96 COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
97 else
98 COMPREPLY=( $(compgen -f -W "${opts} " -- $cur) )
102 diff)
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) )
108 else
109 COMPREPLY=( $(compgen -f -W "${opts} " -- $cur) )
113 log)
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) )
124 else
125 COMPREPLY=( $(compgen -f -W "${opts} " -- $cur) )
128 version)
129 # no options
130 COMPREPLY=()
132 switch)
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) )
142 esac
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: