Properly handle IFS to avoid polluting external value. Remove command lists,
authorOleksandr Gavenko <gavenkoa@gmail.com>
Mon, 06 Mar 2017 11:46:56 +0200
changeset 844 f857121e545c
parent 843 50ca934b19e6
child 845 f286f9ed6c0b
Properly handle IFS to avoid polluting external value. Remove command lists, data recreated from detailed help.
.bash_completion.d/gradle
--- a/.bash_completion.d/gradle	Mon Mar 06 10:22:49 2017 +0200
+++ b/.bash_completion.d/gradle	Mon Mar 06 11:46:56 2017 +0200
@@ -14,36 +14,39 @@
 
 _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 _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 -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.
-help - Displays a help message.
 model - Displays the configuration model.
 projects - Displays the sub-projects.
 properties - Displays the properties.
@@ -52,6 +55,7 @@
 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 resources
@@ -61,14 +65,18 @@
 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
-      local IFS=$'\n'
+      IFS=$'\n'
       COMPREPLY=( $(compgen -W '${_tasks_full}' -- "$cur") )
       if [[ ${#COMPREPLY[@]} -le 1 ]]; then
           COMPREPLY=( ${COMPREPLY[0]%% *-*} )
       fi
-      return
+      IFS=$OIFS; return
   fi
 
   # Perform default option completion for command.
@@ -76,16 +84,16 @@
       case "$prev" in
         help)
           COMPREPLY=( --task )
-          return ;;
+          IFS=$OIFS; return ;;
         init)
           COMPREPLY=( --type )
-          return ;;
+          IFS=$OIFS; return ;;
         wrapper)
           COMPREPLY=( --gradle-version )
-          return ;;
+          IFS=$OIFS; return ;;
         dependencies|dependencyInsight)
           COMPREPLY=( --configuration )
-          return ;;
+          IFS=$OIFS; return ;;
       esac
   fi
 
@@ -108,8 +116,9 @@
     help)
       case "$prev" in
         --task)
-          COMPREPLY=( $(compgen -W '$_help_cmds $_java_cmds $_application_cmds $_other_cmd'  -- $cur) )
-          return ;;
+          echo ${_tasks[@]}
+          COMPREPLY=( $(compgen -W '${_tasks[@]} $_application_cmds'  -- $cur) )
+          IFS=$OIFS; return ;;
       esac
       _extra+=( --task )
       ;;
@@ -117,10 +126,10 @@
       case "$prev" in
         --type)
           COMPREPLY=( $(compgen -W "basic groovy-library java-library pom scala-library" -- "$cur") )
-          return ;;
+          IFS=$OIFS; return ;;
         --test-framework)
           COMPREPLY=( $(compgen -W "spock testng" -- "$cur") )
-          return ;;
+          IFS=$OIFS; return ;;
       esac
       _extra+=( --type --test-framework )
       ;;
@@ -130,24 +139,24 @@
     dependencies)
       case "$prev" in
         --configuration)
-          local IFS=$'\n'
+          IFS=$'\n'
           COMPREPLY=( $(compgen -W '${_configs}' -- "$cur") )
           if [[ ${#COMPREPLY[@]} -le 1 ]]; then
               COMPREPLY=( ${COMPREPLY[0]%% *-*} )
           fi
-          return ;;
+          IFS=$OIFS; return ;;
       esac
       _extra+=( --configuration )
       ;;
     dependencyInsight)
       case "$prev" in
         --configuration)
-          local IFS=$'\n'
+          IFS=$'\n'
           COMPREPLY=( $(compgen -W '${_configs}' -- "$cur") )
           if [[ ${#COMPREPLY[@]} -le 1 ]]; then
               COMPREPLY=( ${COMPREPLY[0]%% *-*} )
           fi
-          return ;;
+          IFS=$OIFS; return ;;
       esac
       _extra+=( --configuration --dependency )
       ;;
@@ -157,12 +166,14 @@
   case "$prev" in
     -I|--init-script|-b|--build-file|-c|--settings-file|-e|--embedded)
       COMPREPLY=( $(compgen -f -- "$cur") )
-      return ;;
+      IFS=$OIFS; return ;;
     -g|--gradle-user-home|-p|--project-dir|--project-cache-dir)
       COMPREPLY=( $(compgen -d -- "$cur") )
-      return ;;
+      IFS=$OIFS; return ;;
   esac
-  COMPREPLY=( $(compgen -W '${_extra[@]} $_opts $_help_cmds $_java_cmds $_application_cmds $_other_cmd' -- $cur) )
+  local _repl=( ${_extra[@]} ${_tasks[@]} $_application_cmds )
+  COMPREPLY=( $(compgen -W '${_repl[@]} $_opts' -- $cur) )
   compopt +o nospace
+  IFS=$OIFS
 } &&
     complete -F _gradle gradle ./gradlew