From 755ea88d5dbaaa4bfee4432bddffc71c422f0cc0 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 14:46:15 +0100 Subject: [PATCH] vmcp: Implement zsh and bash autocompletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add generation of shell autocompletion scripts. Acked-by: Steffen Eiden Reviewed-by: Jan Höppner Signed-off-by: Szabina Korbai Signed-off-by: Jan Höppner --- .gitignore | 2 ++ vmcp/Makefile | 5 +++++ vmcp/autocompletion_generator_host.c | 16 +++++++++++++++ vmcp/vmcp.c | 20 ++----------------- vmcp/vmcp_cli.h | 30 ++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 vmcp/autocompletion_generator_host.c create mode 100644 vmcp/vmcp_cli.h diff --git a/.gitignore b/.gitignore index 5453275d..7d4c266a 100644 --- a/.gitignore +++ b/.gitignore @@ -115,6 +115,8 @@ tunedasd/src/tunedasd tunedasd/src/_tunedasd tunedasd/src/tunedasd.bash vmcp/vmcp +vmcp/_vmcp +vmcp/vmcp.bash vmur/vmur zconf/chp/chchp zconf/chp/lschp diff --git a/vmcp/Makefile b/vmcp/Makefile index b0b5ce66..4175e05a 100644 --- a/vmcp/Makefile +++ b/vmcp/Makefile @@ -1,5 +1,10 @@ include ../common.mak +zsh-completions = _vmcp +bash-completions = vmcp.bash + +include ../common_autocomp.mak + all: vmcp libs = $(rootdir)/libvmcp/libvmcp.a $(rootdir)/libutil/libutil.a diff --git a/vmcp/autocompletion_generator_host.c b/vmcp/autocompletion_generator_host.c new file mode 100644 index 00000000..75020406 --- /dev/null +++ b/vmcp/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "vmcp_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "vmcp"); + + return 0; +} diff --git a/vmcp/vmcp.c b/vmcp/vmcp.c index 10b2361e..de78c9fe 100644 --- a/vmcp/vmcp.c +++ b/vmcp/vmcp.c @@ -36,6 +36,8 @@ #include "lib/util_opt.h" #include "lib/util_prg.h" +#include "vmcp_cli.h" + #define MAXBUFFER 1048576 #define MINBUFFER 4096 #define MAXCMDLEN 240 @@ -50,24 +52,6 @@ static int keep_case = 0; static int buffersize = VMCP_DEFAULT_BUFSZ; static char command[MAXCMDLEN + 1]; -static struct util_opt opt_vec[] = { - UTIL_OPT_SECTION("OPTIONS"), - { - .option = { "keepcase", no_argument, NULL, 'k' }, - .desc = "Do not convert CP-command string to uppercase", - }, - { - .option = { "buffer", required_argument, NULL, 'b' }, - .argument = "SIZE", - .desc = "Specify buffer size in bytes, kilobytes (k) " - "or megabytes (M). SIZE range from 4096 to 1048576 " - "bytes" - }, - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - static const struct util_prg prg = { .desc = "z/VM CP command interface", .args = "CP-command", diff --git a/vmcp/vmcp_cli.h b/vmcp/vmcp_cli.h new file mode 100644 index 00000000..93675668 --- /dev/null +++ b/vmcp/vmcp_cli.h @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef VMCP_CLI_H +#define VMCP_CLI_H + +#include "lib/util_opt.h" + +static struct util_opt opt_vec[] = { + UTIL_OPT_SECTION("OPTIONS"), + { + .option = { "keepcase", no_argument, NULL, 'k' }, + .desc = "Do not convert CP-command string to uppercase", + }, + { + .option = { "buffer", required_argument, NULL, 'b' }, + .argument = "SIZE", + .desc = "Specify buffer size in bytes, kilobytes (k) " + "or megabytes (M). SIZE range from 4096 to 1048576 " + "bytes" + }, + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif