/ bash-completion.bash
bash-completion.bash
 1  # Use git-annex's built-in bash completion
 2  # This is the same code output by git-annex --bash-completion-script git-annex
 3  # This covers all commands, all options, and will never go out of date!
 4  _git-annex()
 5  {
 6      local CMDLINE
 7      local IFS=$'\n'
 8      CMDLINE=(--bash-completion-index $COMP_CWORD)
 9  
10      for arg in ${COMP_WORDS[@]}; do
11          CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
12      done
13  
14      COMPREPLY=( $(git-annex "${CMDLINE[@]}") )
15  }
16  
17  complete -o bashdefault -o default -o filenames -F _git-annex git-annex
18  
19  # Called by git's bash completion script when completing "git annex"
20  # Translate to the "git-annex" completion above.
21  _git_annex() {
22      local CMDLINE
23      CMDLINE=(--bash-completion-index $(($COMP_CWORD - 1)))
24  
25      local seen_git
26      local seen_annex
27      for arg in ${COMP_WORDS[@]}; do
28          if [ "$arg" = git ] && [ -z "$seen_git" ]; then
29  		seen_git=1
30  		CMDLINE=(${CMDLINE[@]} --bash-completion-word git-annex)
31  	elif [ "$arg" = annex ] && [ -z "$seen_annex" ]; then
32  		seen_annex=1
33  	else
34  		CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
35  	fi
36      done
37  
38      # This is the same as __gitcomp_file_direct in git-completion.bash;
39      local IFS=$'\n'
40      COMPREPLY=( $(git-annex "${CMDLINE[@]}") )
41      compopt -o filenames +o nospace ||
42      compgen -f /non-existing-dir/ >/dev/null ||
43      true
44  }