1 #-*- mode: shell-script;-*-
3 # darcs command line completion.
4 # Copyright 2002 "David Roundy" <droundy@abridgegame.org>
10 cur=${COMP_WORDS[COMP_CWORD]}
14 if (($COMP_CWORD == 1)); then
15 COMPREPLY=( $( darcs --commands | grep "^$cur" ) )
19 local IFS=$'\n' # So that the following "command-output to array" operation splits only at newlines, not at each space, tab or newline.
20 COMPREPLY=( $( darcs ${COMP_WORDS[1]} --list-option | grep "^${cur//./\\.}") )
22 # Then, we adapt the resulting strings to be reusable by bash. If we don't
23 # do this, in the case where we have two repositories named
24 # ~/space in there-0.1 and ~/space in there-0.2, the first completion will
26 # bash> darcs push ~/space in there-0.
27 # ~/space in there-0.1 ~/space in there-0.2
28 # and we have introduced two spaces in the command line (if we try to
29 # recomplete that, it won't find anything, as it doesn't know anything
30 # starting with "there-0.").
31 # printf %q will gracefully add the necessary backslashes.
33 # Bash also interprets colon as a separator. If we didn't handle it
34 # specially, completing http://example.org/repo from http://e would
36 # bash> darcs pull http:http://example.org/repo
37 # An option would be to require the user to escape : as \: and we
38 # would do the same here. Instead, we return only the part after
39 # the last colon that is already there, and thus fool bash. The
40 # downside is that bash only shows this part to the user.
41 local i=${#COMPREPLY[*]}
42 local colonprefixes=${cur%"${cur##*:}"}
43 while [ $((--i)) -ge 0 ]; do
44 COMPREPLY[$i]=`printf %q "${COMPREPLY[$i]}"`
46 COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"}
51 [ "$have" ] && complete -F _darcs -o default darcs