python/mach/bash-completion.sh
author Morris Tseng <mtseng@mozilla.com>
Mon, 24 Nov 2014 22:08:00 +0100
changeset 217960 5813ab25249c2a386507946b35c5ebf0990f766c
parent 161298 27cf4fe3975bebfb1add955a2fbccc70c98f7e42
child 453517 729ea50e304585cd0b42ed9138a47b9e7ae68bb0
permissions -rw-r--r--
Bug 1101392 - Part 1: Fix coding style in nsEditorCommands.cpp. r=roc

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