.bash_completion.d/gradle
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 01 Mar 2017 15:43:10 +0200
changeset 841 84ce0f420480
parent 840 92bd6fcf51da
child 842 4ab3110d3c9d
permissions -rw-r--r--
Completion for dependencyInsight. Fix for _extra expansion.

# -*- mode: sh; sh-shell-file: bash -*-

_gradle_cmd()
{
  for ((i = 1; i < $COMP_CWORD; i += 1)); do
    case "${COMP_WORDS[i]}" in
      -*) continue ;;
      *" "*) continue ;;
    esac
    echo "${COMP_WORDS[i]}"
    return
  done
}

_gradle()
{
  local _opts="-? -h --help -A --dep-tasks -C --cache -D --system-prop -I --init-script -P --project-prop -S --full-stacktrace -a --no-rebuild --all \
     -b --build-file -c --settings-file -d --debug -e --embedded -g --gradle-user-home --gui -i --info -m --dry-run --no-opt -p --project-dir \
     -q --quiet -r --properties -s --stacktrace -t --tasks -u --no-search-upward -v --version -x --exclude-task \
     --continue --daemon --foreground --no-color --no-daemon --offline --parallel --parallel-threads --project-cache-dir --recompile-scripts --refresh --refresh-dependencies \
     --rerun-tasks --stop"
  local _help_cmds='components dependencies dependencyInsight buildEnvironment help model projects properties tasks wrapper'
  local _java_cmds='assemble build buildDependents buildNeeded classes compileJava processResources cleanTest jar testClasses compileTestJava processTestResources \
     javadoc check test uploadArchives bootRun'
  local _application_cmds='run startScripts installApp distZip distTar'
  local _other_cmd='clean init install interactive'
  declare -a _extra
  local cur prev
  cur=${COMP_WORDS[COMP_CWORD]}
  [[ $COMP_CWORD != 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}

  # Perform default option completion for command.
  if [[ -z "$curr" ]]; then
      case "$prev" in
        help)
          COMPREPLY=( --task )
          return ;;
        init)
          COMPREPLY=( --type )
          return ;;
        wrapper)
          COMPREPLY=( --gradle-version )
          return ;;
        dependencies|dependencyInsight)
          COMPREPLY=( --configuration )
          return ;;
      esac
  fi

  local _configs="archives              - Configuration for archive artifacts.
compile               - Compile time dependencies.
compileClasspath      - Compile classpath, used when compiling source.
compileOnly           - Compile time only dependencies, not used at runtime.
default               - Dependencies required by this project at runtime.
optional              -
provided              -
runtime               - Runtime dependencies for source set 'main'.
testCompile           - Dependencies for source set 'test'.
testCompileClasspath  - Compile classpath for source set 'test'.
testCompileOnly       - Compile dependencies for source set 'test'.
testRuntime           - Runtime dependencies for source set 'test'."

  # Add or perform command specific completion.
  local _cmd=$(_gradle_cmd)
  case "$_cmd" in
    help)
      case "$prev" in
        --task)
          COMPREPLY=( $(compgen -W '$_help_cmds $_java_cmds $_application_cmds $_other_cmd'  -- $cur) )
          return ;;
      esac
      _extra+=( --task )
      ;;
    init)
      case "$prev" in
        --type)
          COMPREPLY=( $(compgen -W "basic groovy-library java-library pom scala-library" -- "$cur") )
          return ;;
        --test-framework)
          COMPREPLY=( $(compgen -W "spock testng" -- "$cur") )
          return ;;
      esac
      _extra+=( --type --test-framework )
      ;;
    wrapper)
      _extra+=( --gradle-version )
      ;;
    dependencies)
      case "$prev" in
        --configuration)
          local IFS=$'\n'
          COMPREPLY=( $(compgen -W '${_configs}' -- "$cur") )
          if [[ ${#COMPREPLY[@]} -le 1 ]]; then
              COMPREPLY=( ${COMPREPLY[0]%% *-*} )
          fi
          return ;;
      esac
      _extra+=( --configuration )
      ;;
    dependencyInsight)
      case "$prev" in
        --configuration)
          local IFS=$'\n'
          COMPREPLY=( $(compgen -W '${_configs}' -- "$cur") )
          if [[ ${#COMPREPLY[@]} -le 1 ]]; then
              COMPREPLY=( ${COMPREPLY[0]%% *-*} )
          fi
          return ;;
      esac
      _extra+=( --configuration --dependency )
      ;;
  esac

  # Perform generic completion.
  case "$prev" in
    -I|--init-script|-b|--build-file|-c|--settings-file|-e|--embedded)
      COMPREPLY=( $(compgen -f -- "$cur") )
      return ;;
    -g|--gradle-user-home|-p|--project-dir|--project-cache-dir)
      COMPREPLY=( $(compgen -d -- "$cur") )
      return ;;
  esac
  COMPREPLY=( $(compgen -W '${_extra[@]} $_opts $_help_cmds $_java_cmds $_application_cmds $_other_cmd' -- $cur) )
  compopt +o nospace
} &&
    complete -F _gradle gradle ./gradlew