Properly handle IFS to avoid polluting external value. Remove command lists,
data recreated from detailed help.
# -*- 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 OIFS=$IFS 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 _application_cmds='run startScripts installApp distZip distTar' declare -a _extra local cur prev cur=${COMP_WORDS[COMP_CWORD]} [[ $COMP_CWORD -gt 1 ]] && prev=${COMP_WORDS[COMP_CWORD-1]} local _tasks_full='help - Displays a help message.wrapper - Create ./gradlew.assemble - Assembles the outputs of this project.bootRepackage - Repackage existing JAR and WAR archives so that they can be executed from the command line.build - Assembles and tests this project.buildDependents - Assembles and tests this project and all projects that depend on it.buildNeeded - Assembles and tests this project and all projects it depends on.classes - Assembles main classes.compileJava - Compile src/main/java.compileTestJava - Compile src/test/java.processResources - Process src/main/resources.processTestResources - Process src/test/resources.uploadArchives - Deploy build to repository.clean - Deletes the build directory.cleanTest - Delete tests.jar - Assembles a jar archive containing the main classes.testClasses - Assembles test classes.buildEnvironment - Displays all buildscript dependencies.components - Displays the components.dependencies - Displays all dependencies.dependencyInsight - Displays the insight into a specific dependency.model - Displays the configuration model.projects - Displays the sub-projects.properties - Displays the properties.tasks - Displays the tasks runnable from project.cleanIdea - Cleans IDEA project files (IML, IPR)idea - Generates IDEA project files (IML, IPR, IWS)check - Runs all checks.test - Runs the unit tests.init - Generate basic Gradle project files.install - Installs the archives artifacts into the local Maven repository.javadoc - Generates Javadoc API documentation for the main source code.bootRun - Run the project with support for auto-detecting main class and reloading static resourcesflywayBaseline - Baselines an existing database, excluding all migrations up to and including baselineVersion.flywayClean - Drops all objects in the configured schemas.flywayInfo - Prints the details and status information about all the migrations.flywayMigrate - Migrates the schema to the latest version.flywayRepair - Repairs the Flyway metadata table.flywayValidate - Validate applied migrations against resolved ones' IFS=$'\n' local _tasks=( $_tasks_full ) IFS=$' \n' _tasks=( ${_tasks[@]%% -*} ) if [[ $COMP_CWORD = 1 ]] && [[ "$cur" != -* ]]; then IFS=$'\n' COMPREPLY=( $(compgen -W '${_tasks_full}' -- "$cur") ) if [[ ${#COMPREPLY[@]} -le 1 ]]; then COMPREPLY=( ${COMPREPLY[0]%% *-*} ) fi IFS=$OIFS; return fi # Perform default option completion for command. if [[ -z "$curr" ]]; then case "$prev" in help) COMPREPLY=( --task ) IFS=$OIFS; return ;; init) COMPREPLY=( --type ) IFS=$OIFS; return ;; wrapper) COMPREPLY=( --gradle-version ) IFS=$OIFS; return ;; dependencies|dependencyInsight) COMPREPLY=( --configuration ) IFS=$OIFS; 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) echo ${_tasks[@]} COMPREPLY=( $(compgen -W '${_tasks[@]} $_application_cmds' -- $cur) ) IFS=$OIFS; return ;; esac _extra+=( --task ) ;; init) case "$prev" in --type) COMPREPLY=( $(compgen -W "basic groovy-library java-library pom scala-library" -- "$cur") ) IFS=$OIFS; return ;; --test-framework) COMPREPLY=( $(compgen -W "spock testng" -- "$cur") ) IFS=$OIFS; return ;; esac _extra+=( --type --test-framework ) ;; wrapper) _extra+=( --gradle-version ) ;; dependencies) case "$prev" in --configuration) IFS=$'\n' COMPREPLY=( $(compgen -W '${_configs}' -- "$cur") ) if [[ ${#COMPREPLY[@]} -le 1 ]]; then COMPREPLY=( ${COMPREPLY[0]%% *-*} ) fi IFS=$OIFS; return ;; esac _extra+=( --configuration ) ;; dependencyInsight) case "$prev" in --configuration) IFS=$'\n' COMPREPLY=( $(compgen -W '${_configs}' -- "$cur") ) if [[ ${#COMPREPLY[@]} -le 1 ]]; then COMPREPLY=( ${COMPREPLY[0]%% *-*} ) fi IFS=$OIFS; 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") ) IFS=$OIFS; return ;; -g|--gradle-user-home|-p|--project-dir|--project-cache-dir) COMPREPLY=( $(compgen -d -- "$cur") ) IFS=$OIFS; return ;; esac local _repl=( ${_extra[@]} ${_tasks[@]} $_application_cmds ) COMPREPLY=( $(compgen -W '${_repl[@]} $_opts' -- $cur) ) compopt +o nospace IFS=$OIFS} && complete -F _gradle gradle ./gradlew