I am proposing a bash auto-completion script for `jcmd` tool. It covers the 
tedious part of `jcmd` tool usage - <PID|main-class> and command name.

To guess the autocompletion candidates we make intermediate calls to `jcmd` and 
parse the output:
* run "jcmd -l" get a list of running JVMs
* query the list of available diagnostic commands with `jcmd <PID> help`.

The "-o nosort" is set to preserve ordering of candidates: The output from 
autocompletion (on `TAB` key press) is structured. JVM text identification 
<main-class|path-to-jar> immediately follows the PID of this process:

Example with 2 JVMs running:

$ jcmd -l
91936 jdk.jcmd/sun.tools.jcmd.JCmd -l
91668 install/MyApp.jar
91769 EventGeneratorLoop 100
$ jcmd <TAB_key_press>
-l                  --help              91668               install/MyApp.jar   
91769               EventGeneratorLoop


Overall it should greatly improve QoL for `jcmd` Users.

-------------

Commit messages:
 - declare functions consistently
 - more clenup
 - copyright header. minor cleanup
 - 8357439: add bash autocompletion for jcmd

Changes: https://git.openjdk.org/jdk/pull/30606/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=30606&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8357439
  Stats: 157 lines in 1 file changed: 157 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/30606.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/30606/head:pull/30606

PR: https://git.openjdk.org/jdk/pull/30606

Reply via email to