python/mach/bash-completion.sh
author Dustin J. Mitchell <dustin@mozilla.com>
Thu, 20 Jul 2017 19:47:32 +0000
changeset 1192627 ebc0c700e9412aed662cf8752232e35998f7d213
parent 161298 27cf4fe3975bebfb1add955a2fbccc70c98f7e42
child 1807250 2f7b6b3208546b455d6af8dbfae9a55045a45406
permissions -rw-r--r--
Bug 1382707: fix typo MozReview-Commit-ID: 2PhnJojQK8I

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