summaryrefslogtreecommitdiffstats
path: root/python/mach/bash-completion.sh
blob: e4b151f24c95ef482014eb86e1eb5c62aa8b68ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function _mach()
{
  local cur cmds c subcommand
  COMPREPLY=()

  # Load the list of commands
  cmds=`"${COMP_WORDS[0]}" mach-commands`

  # Look for the subcommand.
  cur="${COMP_WORDS[COMP_CWORD]}"
  subcommand=""
  c=1
  while [ $c -lt $COMP_CWORD ]; do
    word="${COMP_WORDS[c]}"
    for cmd in $cmds; do
      if [ "$cmd" = "$word" ]; then
        subcommand="$word"
      fi
    done
    c=$((++c))
  done

  if [[ "$subcommand" == "help" || -z "$subcommand" ]]; then
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
  fi

  return 0
}
complete -o default -F _mach mach