1 # Programmable completion for the Subversion svn command under bash. Source
2 # this file (or on some systems add it to ~/.bash_completion and start a new
3 # shell) and bash's completion mechanism will know all about svn's options!
4 # Provides completion for the svnadmin command as well. Who wants to read
5 # man pages/help text...
7 # Known to work with bash 2.05a with programmable completion and extended
8 # pattern matching enabled (use 'shopt -s extglob progcomp' to enable
9 # these if they are not already enabled).
13 # Tree helper functions which only use bash, to ease readability.
15 # look for value associated to key from stdin in K/V hash file format
16 # val=$(_svn_read_hashfile svn:realmstring < some/file)
17 function _svn_read_hashfile()
19 local tkey=$1 key= val=
22 [ $tag = 'END' ] && break
24 #echo "unexpected tag '$tag' instead of 'K'" >&2
27 read -r -n $len key ; read
30 #echo "unexpected tag '$tag' instead of 'V'" >&2
33 read -r -n $len val ; read
34 if [[ $key = $tkey ]] ; then
39 #echo "target key '$tkey' not found" >&2
42 # _svn_grcut shell-regular-expression
43 # extract filenames from 'svn status' output
47 while read -r line ; do
48 [[ ! $re || $line == $re ]] && echo ${line/???????/}
52 # _svn_lls (dir|file|all) files...
53 # list svn-managed files from list
54 # some 'svn status --all-files' would be welcome here?
60 # could try to check in .svn/entries? hmmm...
61 if [[ $opt == @(dir|all) && -d "$f" ]] ; then
63 elif [[ $opt == @(file|all) ]] ; then
64 # split f in directory/file names
66 [[ "$f" == */* ]] && dn=${f%\/*}/ fn=${f##*\/}
67 # ??? this does not work for just added files, because they
68 # do not have a content reference yet...
69 [ -f "${dn}.svn/text-base/${fn}.svn-base" ] && echo "$f"
74 # This completion guides the command/option order along the one suggested
75 # by "svn help", although other syntaxes are allowed.
77 # - there is a "real" parser to check for what is available and deduce what
78 # can be suggested further.
79 # - the syntax should be coherent with subversion/svn/{cl.h,main.c}
80 # - although it is not a good practice, mixed options and arguments
81 # is supported by the completion as it is by the svn command.
82 # - the completion works in the middle of a line,
83 # but not really in the middle of an argument or option.
84 # - property names are completed: see comments about issues related to handling
85 # ":" within property names although it is a word completion separator.
86 # - unknown properties are assumed to be simple file properties.
87 # - --revprop and --revision options are forced to revision properties
88 # as they are mandatory in this case.
89 # - argument values are suggested to some other options, eg directory names
91 # - values for some options can be extended with environment variables:
92 # SVN_BASH_FILE_PROPS: other properties on files/directories
93 # SVN_BASH_REV_PROPS: other properties on revisions
94 # SVN_BASH_ENCODINGS: encodings to be suggested
95 # SVN_BASH_MIME_TYPE: mime types to be suggested
96 # SVN_BASH_KEYWORDS: "svn:keywords" substitutions to be suggested
97 # SVN_BASH_USERNAME: usernames suggested for --username
98 # SVN_BASH_COMPL_EXT: completion extensions for file arguments, based on the
99 # current subcommand, so that for instance only modified files are
100 # suggested for 'revert', only not svn-managed files for 'add', and so on.
101 # Possible values are:
102 # - username: guess usernames from ~/.subversion/auth/...
103 # - svnstatus: use 'svn status' for completion
104 # - recurse: allow recursion (expensive)
105 # - externals: recurse into externals (very expensive)
106 # Both former options are reasonable, but beware that both later options
107 # may be unadvisable if used on large working copies.
108 # None of these costly completions are activated by default.
109 # Argument completion outside a working copy results in an error message.
110 # Filenames with spaces are not completed properly.
112 # - to do: other options?
113 # obsolete options could be removed from auto-comp? (e.g. -N)
116 local cur cmds cmdOpts pOpts mOpts rOpts qOpts nOpts optsParam opt
119 cur=${COMP_WORDS[COMP_CWORD]}
121 # Possible expansions, without pure-prefix abbreviations such as "up".
122 cmds='add blame annotate praise cat changelist cl \
123 checkout co cleanup commit ci \
124 copy cp delete remove rm diff export help import info \
125 list ls lock log merge mergeinfo mkdir move mv rename \
126 propdel pdel propedit pedit propget pget \
127 proplist plist propset pset resolved revert \
128 status switch unlock update'
130 # help options have a strange command status...
131 local helpOpts='--help -h'
132 # all special options that have a command status
133 local specOpts="--version $helpOpts"
135 # options that require a parameter
136 # note: continued lines must end '|' continuing lines must start '|'
137 optsParam="-r|--revision|--username|--password|--targets|
138 |-x|--extensions|-m|--message|-F|--file|--encoding|
139 |--diff-cmd|--diff3-cmd|--editor-cmd|--old|--new|
140 |--config-dir|--native-eol|-l|--limit|-c|--change|--depth|
141 |--with-revprop|--changelist|--accept"
143 # svn:* and other (env SVN_BASH_*_PROPS) properties
144 local svnProps revProps allProps psCmds propCmds
146 # svn and user configured file properties
147 svnProps="svn:keywords svn:executable svn:needs-lock svn:externals
148 svn:ignore svn:eol-style svn:mime-type $SVN_BASH_FILE_PROPS"
150 # svn and user configured revision properties
151 revProps="svn:author svn:log svn:date $SVN_BASH_REV_PROPS"
153 # all properties as an array variable
154 allProps=( $svnProps $revProps )
156 # subcommands that expect property names
157 psCmds='propset|pset|ps'
158 propCmds="$psCmds|propget|pget|pg|propedit|pedit|pe|propdel|pdel|pd"
160 # Parse arguments and set various variables about what was found.
162 # cmd: the current command if available
163 # isPropCmd: whether it expects a property name argument
164 # isPsCmd: whether it also expects a property value argument
165 # isHelpCmd: whether it is about help
166 # nExpectArgs: how many arguments are expected by the command
167 # help: help requested about this command (if cmd=='help')
168 # prop: property name (if appropriate)
169 # isRevProp: is it a special revision property
170 # val: property value (if appropriate, under pset)
171 # options: all options encountered
172 # hasRevPropOpt: is --revprop set
173 # hasRevisionOpt: is --revision set
174 # hasRelocateOpt: is --relocate set
175 # nargs: how many arguments were found
176 # stat: status of parsing at the 'current' word
178 # prev: previous command in the loop
179 # last: status of last parameter analyzed
181 local cmd= isPropCmd= isPsCmd= isHelpCmd= nExpectArgs= isCur= i=0
182 local prev= help= prop= val= isRevProp= last='none' nargs=0 stat=
183 local options= hasRevPropOpt= hasRevisionOpt= hasRelocateOpt=
185 for opt in "${COMP_WORDS[@]}"
187 # get status of current word (from previous iteration)
188 [[ $isCur ]] && stat=$last
190 # are we processing the current word
192 [[ $i -eq $COMP_CWORD ]] && isCur=1
195 # FIRST must be the "svn" command
196 [ $last = 'none' ] && { last='first'; continue ; }
198 # SKIP option arguments
199 if [[ $prev == @($optsParam) ]] ; then
205 # Argh... This looks like a bashbug...
206 # Redirections are passed to the completion function
207 # although it is managed by the shell directly...
208 # It matters because we want to tell the user when no more
209 # completion is available, so it does not necessary
210 # fallback to the default case.
211 if [[ $prev == @(<|>|>>|[12]>|[12]>>) ]] ; then
219 if [[ ! $cmd && $opt \
220 && ( $opt != -* || $opt == @(${specOpts// /|}) ) ]]
223 [[ $cmd == @($propCmds) ]] && isPropCmd=1
224 [[ $cmd == @($psCmds) ]] && isPsCmd=1
225 [[ $cmd == @(${helpOpts// /|}) ]] && cmd='help'
226 [[ $cmd = 'help' ]] && isHelpCmd=1
227 # HELP about a command asked with an option
228 if [[ $isHelpCmd && $cmd && $cmd != 'help' && ! $help ]]
237 # HELP about a command
238 if [[ $isHelpCmd && ! $help && $opt && $opt != -* ]]
246 if [[ $isPropCmd && ! $prop && $opt && $opt != -* ]]
249 [[ $prop == @(${revProps// /|}) ]] && isRevProp=1
255 if [[ $isPsCmd && $prop && ! $val && $opt != -* ]] ;
262 if [[ $last != 'onlyarg' ]]
266 -r|--revision|--revision=*)
271 # restrict to revision properties!
272 allProps=( $revProps )
273 # on revprops, only one URL is expected
287 # no more options, only arguments, whatever they look like.
288 if [[ $opt = '--' && ! $isCur ]] ; then
293 # options are recorded...
294 if [[ $opt == -* ]] ; then
295 # but not the current one!
296 [[ ! $isCur ]] && options="$options $opt "
306 # then we have an argument
310 [[ $stat ]] || stat=$last
312 # suggest all subcommands, including special help
313 if [[ ! $cmd || $stat = 'cmd' ]]
315 COMPREPLY=( $( compgen -W "$cmds $specOpts" -- $cur ) )
319 # suggest all subcommands
320 if [[ $stat = 'help' || ( $isHelpCmd && ! $help ) ]]
322 COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
326 # help about option arguments
327 if [[ $stat = 'skip' ]]
329 local previous=${COMP_WORDS[COMP_CWORD-1]}
330 local values= dirs= beep=
332 [[ $previous = '--config-dir' ]] && dirs=1
334 [[ $previous = '--native-eol' ]] && values='LF CR CRLF'
336 # just to suggest that a number is expected. hummm.
337 [[ $previous = '--limit' ]] && values='0 1 2 3 4 5 6 7 8 9'
339 # some special partial help about --revision option.
340 [[ $previous = '--revision' || $previous = '-r' ]] && \
341 values='HEAD BASE PREV COMMITTED 0 {'
343 [[ $previous = '--encoding' ]] && \
344 values="latin1 utf8 $SVN_BASH_ENCODINGS"
346 [[ $previous = '--extensions' || $previous = '-x' ]] && \
347 values="--unified --ignore-space-change \
348 --ignore-all-space --ignore-eol-style"
350 [[ $previous = '--depth' ]] && \
351 values='empty files immediates infinity'
353 [[ $previous = '--accept' ]] && \
355 # the list is reduced for 'resolved'
356 if [[ $cmd = 'resolved' ]] ; then
357 values='base mine theirs'
358 else # checkout merge switch update
359 values='postpone base mine theirs edit launch'
363 if [[ $previous = '--username' ]] ; then
364 values="$SVN_BASH_USERNAME"
365 if [[ $SVN_BASH_COMPL_EXT == *username* ]] ; then
368 for file in ~/.subversion/auth/svn.simple/* ; do
369 if [ -r $file ] ; then
370 values="$values $(_svn_read_hashfile username < $file)"
374 [[ ! "$values" ]] && beep=1
377 # could look at ~/.subversion/ ?
378 # hmmm... this option should not exist
379 [[ $previous = '--password' ]] && beep=1
381 # TODO: provide help about other options such as:
382 # --old --new --with-revprop
384 # if the previous option required a parameter, do something
385 # or fallback on ordinary filename expansion
386 [[ $values ]] && COMPREPLY=( $( compgen -W "$values" -- $cur ) )
387 [[ $dirs ]] && COMPREPLY=( $( compgen -o dirnames -- $cur ) )
390 # 'no known completion'. hummm.
397 # provide allowed property names after property commands
398 if [[ $isPropCmd && ( ! $prop || $stat = 'prop' ) && $cur != -* ]]
401 # Ok, this part is pretty ugly.
403 # The issue is that ":" is a completion word separator,
404 # which is a good idea for file:// urls but not within
407 # The first idea was to remove locally ":" from COMP_WORDBREAKS
408 # and then put it back in all cases but in property name
409 # completion. It does not always work. There is a strange bug
410 # where one may get "svn:svn:xxx" in some unclear cases.
412 # Thus the handling is reprogrammed here...
413 # The code assumes that property names look like *:*,
414 # but it also works reasonably well with simple names.
419 # only suggest/show possible suffixes
420 local prefix=${cur%:*} suffix=${cur#*:} c=
421 for c in ${allProps[@]} ; do
422 [[ $c == $prefix:* ]] && choices="$choices ${c#*:}"
424 # everything will be appended to the prefix because ':' is
425 # a separator, so cur is restricted to the suffix part.
428 # only one choice is fine
429 COMPREPLY=( $( compgen -W "${allProps[*]}" -- $cur ) )
430 [ ${#COMPREPLY[@]} -eq 1 ] && return 0
432 # no ':' so only suggest prefixes?
433 local seen= n=0 last= c=
434 for c in ${allProps[@]%:*} ; do
435 # do not put the same prefix twice...
436 if [[ $c == $cur* && ( ! $seen || $c != @($seen) ) ]]
440 choices="$choices $c:"
450 # supply two choices to force a partial completion and a beep
451 [[ $n -eq 1 ]] && choices="$last:1 $last:2"
454 COMPREPLY=( $( compgen -W "$choices" -- $cur ) )
458 # force mandatory --revprop option on revision properties
459 if [[ $isRevProp && ! $hasRevPropOpt ]]
461 COMPREPLY=( $( compgen -W '--revprop' -- $cur ) )
465 # force mandatory --revision option on revision properties
466 if [[ $isRevProp && $hasRevPropOpt && ! $hasRevisionOpt ]]
468 COMPREPLY=( $( compgen -W '--revision' -- $cur ) )
472 # possible completion when setting property values
473 if [[ $isPsCmd && $prop && ( ! $val || $stat = 'val' ) ]]
475 # ' is a reminder for an arbitrary value
476 local values="\' --file"
480 values="Id Rev URL Date Author \' $SVN_BASH_KEYWORDS"
482 svn:executable|svn:needs-lock)
483 # hmmm... canonical value * is special to the shell.
487 values='native LF CR CRLF'
490 # could read /etc/mime.types if available. overkill.
491 values="text/ text/plain text/html text/xml text/rtf
492 image/ image/png image/gif image/jpeg image/tiff
493 audio/ audio/midi audio/mpeg
494 video/ video/mpeg video/mp4
495 application/ application/octet-stream
500 COMPREPLY=( $( compgen -W "$values" -- $cur ) )
501 # special case for --file... return even if within an option
502 [[ ${COMPREPLY} ]] && return 0
505 # maximum number of additional arguments expected in various forms
513 copy|cp|move|mv|rename|ren|export|import)
517 [[ ! $hasRelocateOpt ]] && nExpectArgs=2
527 # the maximum number of arguments is reached for a command
528 if [[ $nExpectArgs && $nargs -gt $nExpectArgs ]]
530 # some way to tell 'no completion at all'... is there a better one?
531 # Do not say 'file completion' here.
537 # if not typing an option,
538 # then fallback on filename expansion...
539 if [[ $cur != -* || $stat = 'onlyarg' ]] ; then
541 # do we allow possible expensive completion here?
542 if [[ $SVN_BASH_COMPL_EXT == *svnstatus* ]] ; then
544 # build status command and options
545 # "--quiet" removes 'unknown' files
546 local status='svn status --non-interactive'
548 [[ $SVN_BASH_COMPL_EXT == *recurse* ]] || \
549 status="$status --non-recursive"
551 # I'm not sure that it can work with externals in call cases
552 # the output contains translatable sentences (even with quiet)
553 [[ $SVN_BASH_COMPL_EXT == *externals* ]] || \
554 status="$status --ignore-externals"
557 # subtlety: must not set $cur* if $cur is empty in some cases
558 [[ $cur ]] && cs=$cur*
560 # 'files' is set according to the current subcommand
562 st*) # status completion must include all files
565 ci|commit|revert|di*) # anything edited
566 files=$($status $cs| _svn_grcut '@([MADR!]*| M*|_M*)')
569 files=$($status $cs| _svn_grcut '\?*')
571 unlock) # unlock locked files
572 files=$($status $cs| _svn_grcut '@(??L*|?????[KOTB]*)')
574 resolved) # files in conflict
575 files=$($status $cs| _svn_grcut '@(?C*|C*)')
577 praise|blame|ann*) # any svn file but added
578 files=$( _svn_lls all $cur* )
581 if [[ $cmd == @($propCmds) && \
582 $prop == @(svn:ignore|svn:externals) ]] ; then
583 # directory specific props
584 files=$( _svn_lls dir . $cur* )
586 # ??? added directories appear twice: foo foo/
587 files="$( _svn_lls all $cur* )
588 $($status $cs | _svn_grcut 'A*' )"
591 info) # information on any file
592 files="$( _svn_lls all $cur* )
593 $($status $cs | _svn_grcut 'A*' )"
595 remove|rm|del*|move|mv|rename) # changing existing files
596 files=$( _svn_lls all $cur* )
598 mkdir) # completion in mkdir can only be for subdirs?
599 files=$( _svn_lls dir $cur* )
601 log|lock|up*|cl*|switch) # misc, all but added files
602 files=$( _svn_lls all $cur* )
604 merge) # may do a better job? URL/WCPATH
605 files=$( _svn_lls all $cur* )
607 ls|list) # better job? what about URLs?
608 files=$( _svn_lls all $cur* )
610 *) # other commands: changelist export import cat mergeinfo
615 # when not recursive, some relevant files may exist
616 # within subdirectories, so they are added here.
617 # should it be restricted to svn-managed subdirs? no??
618 if [[ $SVN_BASH_COMPL_EXT != *recurse* ]] ; then
619 files="$files $( _svn_lls dir $cur* )"
622 # set completion depending on computed 'files'
623 if [[ $files ]] ; then
624 COMPREPLY=( $( compgen -W "$files" -- $cur ) )
625 # if empty, set to nope?
626 [[ "${COMPREPLY[*]}" ]] || COMPREPLY=( '' )
627 elif [[ ! $fallback ]] ; then
628 # this suggests no completion...
633 # else fallback to ordinary filename completion...
637 # otherwise build possible options for the command
638 pOpts="--username --password --no-auth-cache --non-interactive"
639 mOpts="-m --message -F --file --encoding --force-log --with-revprop"
640 rOpts="-r --revision"
642 nOpts="-N --non-recursive --depth"
643 gOpts="-g --use-merge-history"
651 cmdOpts="--auto-props --no-auto-props --force --targets \
652 --no-ignore $nOpts $qOpts"
654 blame|annotate|ann|praise)
655 cmdOpts="$rOpts $pOpts -v --verbose --incremental --xml \
656 -x --extensions --force $gOpts"
659 cmdOpts="$rOpts $pOpts"
662 cmdOpts="--clear --targets"
665 cmdOpts="$rOpts $qOpts $nOpts $pOpts --ignore-externals \
669 cmdOpts="--diff3-cmd"
672 cmdOpts="$mOpts $qOpts $nOpts --targets --editor-cmd $pOpts \
673 --no-unlock --changelist --keep-changelist"
676 cmdOpts="$mOpts $rOpts $qOpts --editor-cmd $pOpts $gOpts"
678 delete|del|remove|rm)
679 cmdOpts="--force $mOpts $qOpts --targets --editor-cmd $pOpts"
682 cmdOpts="$rOpts -x --extensions --diff-cmd --no-diff-deleted \
683 $nOpts $pOpts --force --old --new --notice-ancestry \
684 -c --change --summarize"
687 cmdOpts="$rOpts $qOpts $pOpts $nOpts --force --native-eol \
694 cmdOpts="--auto-props --no-auto-props $mOpts $qOpts $nOpts \
695 --no-ignore --editor-cmd $pOpts"
698 cmdOpts="$pOpts $rOpts --targets -R --recursive \
699 --incremental --xml --changelist"
702 cmdOpts="$rOpts -v --verbose -R --recursive $pOpts \
706 cmdOpts="$mOpts --targets --force $pOpts"
709 cmdOpts="$rOpts -v --verbose --targets $pOpts --stop-on-copy \
710 --incremental --xml $qOpts -l --limit --changelist \
714 cmdOpts="$rOpts $nOpts $qOpts --force --dry-run --diff3-cmd \
715 $pOpts --ignore-ancestry -c --change -x --extensions \
716 --record-only --accept"
719 cmdOpts="$rOpts $pOpts"
722 cmdOpts="$mOpts $qOpts --editor-cmd $pOpts"
725 cmdOpts="$mOpts $rOpts $qOpts --force --editor-cmd $pOpts \
729 cmdOpts="$qOpts -R --recursive $rOpts $pOpts"
730 [[ $isRevProp || ! $prop ]] && cmdOpts="$cmdOpts --revprop"
733 cmdOpts="--encoding --editor-cmd $pOpts --force"
734 [[ $isRevProp || ! $prop ]] && \
735 cmdOpts="$cmdOpts --revprop $rOpts"
738 cmdOpts="-R --recursive $rOpts --strict $pOpts"
739 [[ $isRevProp || ! $prop ]] && cmdOpts="$cmdOpts --revprop"
742 cmdOpts="-v --verbose -R --recursive $rOpts --revprop $qOpts \
746 cmdOpts="$qOpts --targets -R --recursive \
747 --encoding $pOpts --force"
748 [[ $isRevProp || ! $prop ]] && \
749 cmdOpts="$cmdOpts --revprop $rOpts"
750 [[ $val ]] || cmdOpts="$cmdOpts -F --file"
753 cmdOpts="--targets -R --recursive $qOpts --accept"
756 cmdOpts="--targets -R --recursive $qOpts --changelist"
759 cmdOpts="-u --show-updates -v --verbose $nOpts $qOpts $pOpts \
760 --no-ignore --ignore-externals --incremental --xml"
763 cmdOpts="--relocate $rOpts $nOpts $qOpts $pOpts --diff3-cmd \
767 cmdOpts="--targets --force $pOpts"
770 cmdOpts="$rOpts $nOpts $qOpts $pOpts --diff3-cmd \
771 --ignore-externals --force --accept"
777 # add options that are nearly always available
778 [[ "$cmd" != "--version" ]] && cmdOpts="$cmdOpts $helpOpts"
779 cmdOpts="$cmdOpts --config-dir"
781 # take out options already given
786 # remove leading dashes and arguments
788 --*) optBase=${opt/=*/} ;;
789 -*) optBase=${opt:0:2} ;;
793 cmdOpts=${cmdOpts/ ${optBase} / }
795 # take out alternatives and mutually exclusives
797 -v) cmdOpts=${cmdOpts/ --verbose / } ;;
798 --verbose) cmdOpts=${cmdOpts/ -v / } ;;
799 -N) cmdOpts=${cmdOpts/ --non-recursive / } ;;
800 --non-recursive) cmdOpts=${cmdOpts/ -N / } ;;
801 -R) cmdOpts=${cmdOpts/ --recursive / } ;;
802 --recursive) cmdOpts=${cmdOpts/ -R / } ;;
803 -x) cmdOpts=${cmdOpts/ --extensions / } ;;
804 --extensions) cmdOpts=${cmdOpts/ -x / } ;;
805 -q) cmdOpts=${cmdOpts/ --quiet / } ;;
806 --quiet) cmdOpts=${cmdOpts/ -q / } ;;
807 -h) cmdOpts=${cmdOpts/ --help / } ;;
808 --help) cmdOpts=${cmdOpts/ -h / } ;;
809 -l) cmdOpts=${cmdOpts/ --limit / } ;;
810 --limit) cmdOpts=${cmdOpts/ -l / } ;;
811 -r) cmdOpts=${cmdOpts/ --revision / } ;;
812 --revision) cmdOpts=${cmdOpts/ -r / } ;;
813 -c) cmdOpts=${cmdOpts/ --change / } ;;
814 --change) cmdOpts=${cmdOpts/ -c / } ;;
815 --auto-props) cmdOpts=${cmdOpts/ --no-auto-props / } ;;
816 --no-auto-props) cmdOpts=${cmdOpts/ --auto-props / } ;;
817 -g) cmdOpts=${cmdOpts/ --use-merge-history / } ;;
819 cmdOpts=${cmdOpts/ -g / } ;;
820 -m|--message|-F|--file)
821 cmdOpts=${cmdOpts/ --message / }
822 cmdOpts=${cmdOpts/ -m / }
823 cmdOpts=${cmdOpts/ --file / }
824 cmdOpts=${cmdOpts/ -F / }
828 # remove help options within help subcommand
829 if [ $isHelpCmd ] ; then
830 cmdOpts=${cmdOpts/ -h / }
831 cmdOpts=${cmdOpts/ --help / }
835 # provide help about available options
836 COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )
839 complete -F _svn -o default -X '@(*/.svn|*/.svn/|.svn|.svn/)' svn
843 local cur cmds cmdOpts optsParam opt helpCmds optBase i
846 cur=${COMP_WORDS[COMP_CWORD]}
848 # Possible expansions, without pure-prefix abbreviations such as "h".
849 cmds='crashtest create deltify dump help hotcopy list-dblogs \
850 list-unused-dblogs load lslocks lstxns recover rmlocks \
851 rmtxns setlog verify --version'
853 if [[ $COMP_CWORD -eq 1 ]] ; then
854 COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
858 # options that require a parameter
859 # note: continued lines must end '|' continuing lines must start '|'
860 optsParam="-r|--revision|--parent-dir|--fs-type"
862 # if not typing an option, or if the previous option required a
863 # parameter, then fallback on ordinary filename expansion
864 helpCmds='help|--help|h|\?'
865 if [[ ${COMP_WORDS[1]} != @($helpCmds) ]] && \
866 [[ "$cur" != -* ]] || \
867 [[ ${COMP_WORDS[COMP_CWORD-1]} == @($optsParam) ]] ; then
872 case ${COMP_WORDS[1]} in
874 cmdOpts="--bdb-txn-nosync --bdb-log-keep --config-dir \
875 --fs-type --pre-1.4-compatible"
878 cmdOpts="-r --revision -q --quiet"
881 cmdOpts="-r --revision --incremental -q --quiet --deltas"
884 cmdOpts="$cmds -q --quiet"
887 cmdOpts="--clean-logs"
890 cmdOpts="--ignore-uuid --force-uuid --parent-dir -q --quiet \
891 --use-pre-commit-hook --use-post-commit-hook"
900 cmdOpts="-r --revision --bypass-hooks"
906 cmdOpts="$cmdOpts --help -h"
908 # take out options already given
909 for (( i=2; i<=$COMP_CWORD-1; ++i )) ; do
910 opt=${COMP_WORDS[$i]}
913 --*) optBase=${opt/=*/} ;;
914 -*) optBase=${opt:0:2} ;;
918 cmdOpts=${cmdOpts/ ${optBase} / }
920 # take out alternatives
922 -q) cmdOpts=${cmdOpts/ --quiet / } ;;
923 --quiet) cmdOpts=${cmdOpts/ -q / } ;;
924 -h) cmdOpts=${cmdOpts/ --help / } ;;
925 --help) cmdOpts=${cmdOpts/ -h / } ;;
926 -r) cmdOpts=${cmdOpts/ --revision / } ;;
927 --revision) cmdOpts=${cmdOpts/ -r / } ;;
930 # skip next option if this one requires a parameter
931 if [[ $opt == @($optsParam) ]] ; then
936 COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )
940 complete -F _svnadmin -o default svnadmin