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--from | --to | --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 ;;
189diff )
190 COMPREPLY=( $(compgen -W '--context --depth --diff-args
191 --exclude --external --no-show-encloser --unified
192 --revision -r' -- $cur ) )
193 _filedir
194 ;;
195annotate )
196 COMPREPLY=( $(compgen -W '--brief --revision -r' -- $cur ) )
197 _filedir
198 ;;
199log )
200 COMPREPLY=( $(compgen -W '--brief --diffs --from --last
201 --next --no-files --no-graph --no-merges --to' -- $cur ) )
202 _filedir
203 ;;
204approve | disapprove | comment | suspend | tag | testresult | cert | explicit_merge | trusted | update )
205 _monotone_complete revision
206 ;;
207ls | list )
208 COMPREPLY=( $(compgen -W 'branches certs changed epochs
209 keys known missing tags ignored unknown vars' -- $cur ) )
210 ;;
211attr )
212 COMPREPLY=( $(compgen -W 'get set drop' -- $cur ) )
213 ;;
214co | checkout )
215 _filedir -d
216 _monotone_complete revision
217 ;;
218status | cvs_import | add | drop | rm | rename | mv | revert | identify )
219 _filedir
220 ;;
221complete )
222 COMPREPLY=( $(compgen -W 'revision manifest file key' -- $cur) )
223 ;;
224cat )
225 _filedir
226 ;;
227clone | push | pull | serve | sync )
228 COMPREPLY=( $(compgen -A hostname -- $cur) )
229 ;;
230pubkey | privkey )
231 _monotone_keys "$prev"
232 ;;
233passphrase | dropkey )
234 _monotone_keys privkey
235 ;;
236propagate | reindex )
237 _monotone_branches
238 ;;
239* )
240 if (( $COMP_CWORD >= 2 )) ; then
241local prev2=${COMP_WORDS[COMP_CWORD-2]}
242case "$prev2" in
243 diff | explicit_merge )
244_monotone_complete revision
245;;
246 co | checkout | rename | mv | annotate )
247_filedir
248;;
249 attr )
250_filedir
251;;
252 list )
253if [ "$prev" == certs ] ; then
254 _monotone_complete revision
255 _monotone_complete manifest
256 _monotone_complete file
257fi
258;;
259 clone | push | pull | serve | sync | propagate )
260_monotone_branches
261;;
262 * )
263if (( $COMP_CWORD >= 3 )) ; then
264 local prev3=${COMP_WORDS[COMP_CWORD-3]}
265 case "$prev3" in
266explicit_merge )
267 _monotone_complete revision
268 _monotone_branches
269 ;;
270*)
271 unset prev2
272 unset prev3
273 _filedir
274 esac
275else
276 unset prev2
277 _filedir
278fi
279;;
280esac
281 fi
282 if (( $COMP_CWORD < 2 )) ; then
283COMPREPLY=( $(compgen -W '
284 automate
285 db
286 fdiff fload fmerge get_roster identify rcs_import
287 annotate cat complete diff help list log ls show_conflicts
288 status
289 cert passphrase dropkey genkey trusted
290 clone pull push serve sync
291 privkey pubkey read
292 cvs_import
293 approve comment disapprove suspend tag testresult
294 checkout co explicit_merge heads merge merge_into_dir
295 migrate_workspace propagate refresh_inodeprints setup
296 set unset
297 add attr ci commit drop mv pivot_root pluck rename revert
298 rm update
299 ' -- $cur) )
300 fi
301 ;;
302 esac
303 ;;
304 esac
305 return 0
306}
307
308complete -F _monotone -o filenames mtn

Archive Download this file

Branches

Tags

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