All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 # bash completion for vcsh.
4 # based on bash_completion:_command_offset()
7 for (( i=0; i < $word_offset; i++ )); do
8 for (( j=0; j <= ${#COMP_LINE}; j++ )); do
9 [[ "$COMP_LINE" == "${COMP_WORDS[i]}"* ]] && break
10 COMP_LINE=${COMP_LINE:1}
13 COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
14 ((COMP_POINT-=${#COMP_WORDS[i]}))
16 COMP_LINE="git $COMP_LINE"
19 # shift COMP_WORDS elements and adjust COMP_CWORD
20 for (( i=1; i <= COMP_CWORD - $word_offset + 1; i++ )); do
21 COMP_WORDS[i]=${COMP_WORDS[i+$word_offset-1]}
23 for (( i; i <= COMP_CWORD; i++ )); do
27 ((COMP_CWORD -= $word_offset - 1))
29 local cspec=$( complete -p git 2>/dev/null )
30 if [[ -n $cspec ]]; then
31 if [[ ${cspec#* -F } != $cspec ]]; then
32 local func=${cspec#*-F }
35 if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
36 $func git "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
38 $func git "${COMP_WORDS[${#COMP_WORDS[@]}-1]}"
41 # restore initial compopts
43 while [[ $cspec == *" -o "* ]]; do
44 # FIXME: should we take "+o opt" into account?
55 local cur prev words cword OPTS
56 _init_completion -n = || return
59 repos=( $(command vcsh list) )
60 cmds="clone delete enter foreach help init list list-tracked list-untracked
61 pull push rename run status upgrade version which write-gitignore"
63 local subcword cmd subcmd
64 for (( subcword=1; subcword < ${#words[@]}-1; subcword++ )); do
65 [[ -n $cmd && ${words[subcword]} != -* ]] && subcmd=${words[subcword]} && break
66 [[ ${words[subcword]} != -* ]] && cmd=${words[subcword]}
69 if [[ -z $cmd ]]; then
72 COMPREPLY=( $(compgen -f -- $cur) )
80 COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
84 COMPREPLY=( $(compgen -W "${repos[*]} ${cmds[*]}" -- $cur) )
89 help|init|list|pull|push|version|which)
95 COMPREPLY=( $(compgen -W '-a -r' -- $cur) ) && return
99 if [[ -n $subcmd && -n "${repos[$subcmd]}" ]]; then
100 _command_offset $(( $subcword+1 ))
105 delete|enter|list-tracked|list-untracked|rename|run|status|upgrade|write-gitignore)
107 if [[ -z $subcmd ]]; then
108 COMPREPLY=( $(compgen -W "${repos[*]}" -- $cur) )
115 [[ $cur == -* ]] && \
116 COMPREPLY=( $(compgen -W '-b' -- $cur) )
122 && COMPREPLY=( $(compgen -W "-g" -- $cur) ) && return
123 _vcsh_git_command $subcword
129 # git command on repository
130 if [[ -n "${repos[$cmd]}" ]]; then
131 _vcsh_git_command $subcword
136 complete -F _vcsh vcsh