monotone

monotone Mtn Source Tree

Root/contrib/monotone.bash_completion

1# -*- shell-script -*-
2# vim: set ft=sh sw=4 et:
3
4# bash completion for monotone 0.25
5# Author: Olivier Andrieu <oandrieu@nerim.net>
6# Contributions by Matthew A. Nicholson <matt@matt-land.com>
7# and Matthew Sackman <matthew@wellquite.org>
8
9# source this file from your .bashrc
10# If you use the bash completion package <http://www.caliban.org/bash/>,
11# copy this file in the directory /etc/bash_completion.d for a
12# system-wide install
13
14
15# The function _filedir is defined in /etc/bash_completion.
16# This is a weaker version, for those who do not have the
17# bash completion package installed.
18if ! type _filedir >& /dev/null ; then
19_filedir() {
20 local IFS=$'\t\n' arg
21 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen ${1:--f} -- $cur) )
22}
23fi
24
25_monotone_previous_RETURN=`trap -p RETURN`
26_monotone_previous_SIGHUP=`trap -p SIGHUP`
27_monotone_previous_SIGINT=`trap -p SIGINT`
28_monotone_previous_SIGPIPE=`trap -p SIGPIPE`
29_monotone_previous_SIGTERM=`trap -p SIGTERM`
30if shopt -q extglob; then :; else
31 shopt -s extglob
32 trap "shopt -u extglob; ${_monotone_previous_RETURN:-trap - RETURN}; ${_monotone_previous_SIGHUP:-trap - SIGHUP}; ${_monotone_previous_SIGINT:-trap - SIGINT}; ${_monotone_previous_SIGPIPE:-trap - SIGPIPE}; ${_monotone_previous_SIGTERM:-trap - SIGTERM}" RETURN SIGHUP SIGINT SIGPIPE SIGTERM
33fi
34
35# Call monotone to complete IDs
36_monotone_complete() {
37 if (( "${#cur}" >=2 )) ; then
38COMPREPLY=( ${COMPREPLY[@]:-} $(mtn $mono_db complete $1 $cur 2> /dev/null) )
39 fi
40}
41
42# Call monotone to complete key ids (private or public)
43_monotone_keys() {
44 local range
45 if [ "$1" == "privkey" ]; then
46range='/\[private/,$'
47 else
48range='1,/\[private/'
49 fi
50 COMPREPLY=( $(compgen -W "$(mtn $mono_db list keys 2> /dev/null |\
51 sed -n ${range}'{/^[0-9a-f]/s/[0-9a-f]* //p}')" -- ${cur#*=} ) )
52}
53
54_monotone_branches() {
55 COMPREPLY=( $(compgen -W "$(mtn $mono_db list branches 2> /dev/null)" -- ${cur#*=} ) )
56}
57
58_monotone_tags() {
59 COMPREPLY=( $(compgen -W "$(mtn $mono_db list tags 2> /dev/null | awk '{print $1}')" -- ${cur#*=} ) )
60}
61
62_monotone() {
63 local cur prev mono_db
64
65 for w in ${COMP_WORDS[@]} ; do
66if [[ "$w" == --db=* ]] ; then
67 mono_db="$w" ; break
68fi
69 done
70 if [ -z "$mono_db" ] ; then
71for i in ${!COMP_WORDS[@]} ; do
72 [ $i -eq 0 ] && continue
73 prev="${COMP_WORDS[$i-1]}"
74 if [ "$prev" == --db -o "$prev" == -d ] ; then
75mono_db="--db=${COMP_WORDS[$i]}" ; break
76 fi
77done
78 fi
79
80 cur=${COMP_WORDS[COMP_CWORD]}
81 prev=${COMP_WORDS[COMP_CWORD-1]}
82
83 case $cur in
84*/a:!(*/[[:alpha:]]:*) | *=a:!(*/[[:alpha:]]:*) | a:!(*/[[:alpha:]]:*) )
85 cur="${cur##*a:}"
86 _monotone_keys pubkey
87 ;;
88*/b:!(*/[[:alpha:]]:*) | *=b:!(*/[[:alpha:]]:*) | b:!(*/[[:alpha:]]:*) )
89 cur="${cur##*b:}"
90 _monotone_branches
91 ;;
92 */h:!(*/[[:alpha:]]:*) | *=h:!(*/[[:alpha:]]:*) | h:!(*/[[:alpha:]]:*) )
93 cur="${cur##*h:}"
94 _monotone_branches
95 ;;
96*/i:!(*/[[:alpha:]]:*) | *=i:!(*/[[:alpha:]]:*) | i:!(*/[[:alpha:]]:*) )
97 cur="${cur##*i:}"
98 _monotone_complete revision
99 ;;
100*/t:!(*/[[:alpha:]]:*) | *=t:!(*/[[:alpha:]]:*) | t:!(*/[[:alpha:]]:*) )
101 cur="${cur##*t:}"
102 _monotone_tags
103 ;;
104--db=* | --rcfile=* | --dump=* )
105 cur="${cur#*=}"
106 _filedir
107 ;;
108--root=* )
109 cur="${cur#*=}"
110 _filedir -d
111 ;;
112--branch=* )
113 _monotone_branches
114 ;;
115--key=* )
116 _monotone_keys pubkey
117 ;;
118--ticker=* )
119 cur="${cur#*=}"
120 COMPREPLY=( $(compgen -W 'count dot none' -- $cur ) )
121 ;;
122--revision=* )
123 cur="${cur#*=}"
124 _monotone_complete revision
125 ;;
126-* )
127 COMPREPLY=( $(compgen -W '
128 --brief
129 --confdir
130 --db -d
131 --debug
132 --dump
133 --full-version
134 --help -h
135 --key -k
136 --keydir
137 --log
138 --norc
139 --nostd
140 --pid-file
141 --quiet
142 --rcfile
143 --rellyquiet
144 --root
145 --ticker
146 --version
147 --xargs -@
148 --version
149
150 --message -m
151 --branch -b
152 --revision -r
153 --date
154 --author
155 --depth
156 --execute -e
157
158 --exclude
159 --key-to-push
160 --set-default
161
162 --bind
163 ' -- $cur) )
164 ;;
165 * )
166 case "$prev" in
167--db | -d | --rcfile | --dump | --root )
168 _filedir
169 ;;
170--branch | -b )
171 _monotone_branches
172 ;;
173--key | -k )
174 _monotone_keys pubkey
175 ;;
176--ticker )
177 COMPREPLY=( $(compgen -W 'count dot none' -- $cur ) )
178 ;;
179--revision | -r )
180 _monotone_complete revision
181 ;;
182db )
183 COMPREPLY=( $(compgen -W 'init info version dump load
184 migrate execute
185 kill_rev_locally kill_branch_certs_locally
186 kill_tag_locally check changesetify rosterify
187 regenerate_caches set_epoch' -- $cur ) )
188 ;;
189cdiff | diff | annotate )
190 COMPREPLY=( $(compgen -W '--revision -r' -- $cur ) )
191 _filedir
192 ;;
193log )
194 COMPREPLY=( $(compgen -W '--brief --diffs --last --next
195 --no-files --no-merges --revision -r' -- $cur ) )
196 _filedir
197 ;;
198approve | disapprove | comment | tag | testresult | cert | explicit_merge | trusted | update )
199 _monotone_complete revision
200 ;;
201ls | list )
202 COMPREPLY=( $(compgen -W 'certs keys branches epochs tags vars known unknown ignored missing' -- $cur ) )
203 ;;
204attr )
205 COMPREPLY=( $(compgen -W 'get set drop' -- $cur ) )
206 ;;
207co | checkout )
208 _filedir -d
209 _monotone_complete revision
210 ;;
211status | cvs_import | add | drop | rm | rename | mv | revert | identify )
212 _filedir
213 ;;
214complete )
215 COMPREPLY=( $(compgen -W 'revision manifest file key' -- $cur) )
216 ;;
217cat )
218 COMPREPLY=( $(compgen -W 'file manifest revision' -- $cur) )
219 ;;
220push | pull | serve | sync )
221 COMPREPLY=( $(compgen -A hostname -- $cur) )
222 ;;
223pubkey | privkey )
224 _monotone_keys "$prev"
225 ;;
226chkeypass | dropkey )
227 _monotone_keys privkey
228 ;;
229propagate | reindex )
230 _monotone_branches
231 ;;
232* )
233 if (( $COMP_CWORD >= 2 )) ; then
234local prev2=${COMP_WORDS[COMP_CWORD-2]}
235case "$prev2" in
236 cdiff | diff | explicit_merge )
237_monotone_complete revision
238;;
239 co | checkout | rename | mv | annotate )
240_filedir
241;;
242 cat )
243_monotone_complete "$prev"
244;;
245 attr )
246_filedir
247;;
248 list )
249if [ "$prev" == certs ] ; then
250 _monotone_complete revision
251 _monotone_complete manifest
252 _monotone_complete file
253fi
254;;
255 push | pull | serve | sync | propagate )
256_monotone_branches
257;;
258 * )
259if (( $COMP_CWORD >= 3 )) ; then
260 local prev3=${COMP_WORDS[COMP_CWORD-3]}
261 case "$prev3" in
262explicit_merge )
263 _monotone_complete revision
264 _monotone_branches
265 ;;
266*)
267 unset prev2
268 unset prev3
269 _filedir
270 esac
271else
272 unset prev2
273 _filedir
274fi
275;;
276esac
277 fi
278 if (( $COMP_CWORD < 2 )) ; then
279COMPREPLY=( $(compgen -W '
280 automate
281 db
282 fdiff fload fmerge get_roster identify rcs_import
283 annotate cat complete diff help list log ls show_conflicts
284 status
285 cert chkeypass dropkey genkey trusted
286 pull push serve sync
287 privkey pubkey read
288 cvs_import
289 approve comment disapprove tag testresult
290 checkout co explicit_merge heads merge merge_into_dir
291 migrate_workspace propagate refresh_inodeprints setup
292 set unset
293 add attr ci commit drop mv pivot_root pluck rename revert
294 rm update
295 ' -- $cur) )
296 fi
297 ;;
298 esac
299 ;;
300 esac
301 return 0
302}
303
304complete -F _monotone -o filenames mtn

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status