#
# bash completion support for core Git.
#
-# Copyright (C) 2006 Shawn Pearce
+# Copyright (C) 2006,2007 Shawn Pearce
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
#
# The contained completion routines provide support for completing:
fi
}
+__gitcomp ()
+{
+ local all c s=$'\n' IFS=' '$'\t'$'\n'
+ for c in $1; do
+ case "$c" in
+ --*=*) all="$all$c$s" ;;
+ *) all="$all$c $s" ;;
+ esac
+ done
+ IFS=$s
+ COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}"))
+ return
+}
+
__git_heads ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
for i in $(git help -a|egrep '^ ')
do
case $i in
+ add--interactive) : plumbing;;
+ cat-file) : plumbing;;
check-ref-format) : plumbing;;
commit-tree) : plumbing;;
convert-objects) : plumbing;;
peek-remote) : plumbing;;
read-tree) : plumbing;;
receive-pack) : plumbing;;
+ reflog) : plumbing;;
rerere) : plumbing;;
rev-list) : plumbing;;
rev-parse) : plumbing;;
COMPREPLY=()
}
-_git_branch ()
+_git_add ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
- COMPREPLY=($(compgen -W "-l -f -d -D $(__git_refs)" -- "$cur"))
+ case "$cur" in
+ --*)
+ COMPREPLY=($(compgen -W "
+ --interactive
+ " -- "$cur"))
+ return
+ esac
+ COMPREPLY=()
}
-_git_cat_file ()
+_git_branch ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
- case "${COMP_WORDS[0]},$COMP_CWORD" in
- git-cat-file*,1)
- COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
- ;;
- git,2)
- COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
- ;;
- *)
- __git_complete_file
- ;;
- esac
+ COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
}
_git_checkout ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
- COMPREPLY=($(compgen -W "-l -b $(__git_refs)" -- "$cur"))
+ COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
}
_git_cherry_pick ()
_git_diff_tree ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
- COMPREPLY=($(compgen -W "-r -p -M $(__git_refs)" -- "$cur"))
+ COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
}
_git_fetch ()
done
if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
- COMPREPLY=($(compgen -W "
- --git-dir= --version --exec-path
- $(__git_commands)
- $(__git_aliases)
- " -- "${COMP_WORDS[COMP_CWORD]}"))
- return;
+ case "${COMP_WORDS[COMP_CWORD]}" in
+ --*=*) COMPREPLY=() ;;
+ --*) __gitcomp "--git-dir= --bare --version --exec-path" ;;
+ *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
+ esac
+ return
fi
local expansion=$(__git_aliased_command "$command")
case "$command" in
am) _git_am ;;
+ add) _git_add ;;
apply) _git_apply ;;
branch) _git_branch ;;
- cat-file) _git_cat_file ;;
checkout) _git_checkout ;;
cherry-pick) _git_cherry_pick ;;
commit) _git_commit ;;
complete -o default -F _git_am git-am
complete -o default -F _git_apply git-apply
complete -o default -F _git_branch git-branch
-complete -o default -o nospace -F _git_cat_file git-cat-file
complete -o default -F _git_checkout git-checkout
complete -o default -F _git_cherry_pick git-cherry-pick
complete -o default -F _git_commit git-commit
# included the '.exe' suffix.
#
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
+complete -o default -F _git_add git-add.exe
complete -o default -F _git_apply git-apply.exe
complete -o default -o nospace -F _git git.exe
complete -o default -F _git_branch git-branch.exe
-complete -o default -o nospace -F _git_cat_file git-cat-file.exe
complete -o default -o nospace -F _git_diff git-diff.exe
complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
complete -o default -o nospace -F _git_format_patch git-format-patch.exe