From 7730f2489f2ac524c54cc7d2cc94a1a91cef0dbd Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 16:54:38 +0100 Subject: [PATCH] zipl-editenv: 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 + zipl/src/Makefile | 5 ++ zipl/src/autocompletion_generator_host.c | 16 +++++++ zipl/src/zipl-editenv.c | 59 ++++-------------------- zipl/src/zipl_editenv_cli.h | 58 +++++++++++++++++++++++ 5 files changed, 89 insertions(+), 51 deletions(-) create mode 100644 zipl/src/autocompletion_generator_host.c create mode 100644 zipl/src/zipl_editenv_cli.h diff --git a/.gitignore b/.gitignore index 9b126a70..f7cfc1e4 100644 --- a/.gitignore +++ b/.gitignore @@ -167,6 +167,8 @@ zipl/src/chreipl_helper.device-mapper zipl/src/chreipl_helper.md zipl/src/zipl zipl/src/zipl-editenv +zipl/src/_zipl-editenv +zipl/src/zipl-editenv.bash zipl/src/zipl_helper.device-mapper zipl/src/zipl_helper.md zkey/check-dep-zkey diff --git a/zipl/src/Makefile b/zipl/src/Makefile index 39489e2e..9a9b4991 100644 --- a/zipl/src/Makefile +++ b/zipl/src/Makefile @@ -1,6 +1,11 @@ # Common definitions include ../../common.mak +zsh-completions = _zipl-editenv +bash-completions = zipl-editenv.bash + +include ../../common_autocomp.mak + ALL_CPPFLAGS += -I../include -I../boot \ -DZFCPDUMP_IMAGE="STRINGIFY($(ZFCPDUMP_DIR)/$(ZFCPDUMP_IMAGE))" \ -DZFCPDUMP_INITRD="STRINGIFY($(ZFCPDUMP_DIR)/$(ZFCPDUMP_INITRD))" \ diff --git a/zipl/src/autocompletion_generator_host.c b/zipl/src/autocompletion_generator_host.c new file mode 100644 index 00000000..3917a196 --- /dev/null +++ b/zipl/src/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "zipl_editenv_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "zipl-editenv"); + + return 0; +} diff --git a/zipl/src/zipl-editenv.c b/zipl/src/zipl-editenv.c index 58c4da6a..ba640b25 100644 --- a/zipl/src/zipl-editenv.c +++ b/zipl/src/zipl-editenv.c @@ -18,17 +18,20 @@ #include #include #include -#include "disk.h" -#include "error.h" -#include "misc.h" -#include "bootmap.h" -#include "envblk.h" + #include "lib/util_prg.h" #include "lib/util_opt.h" #include "lib/util_part.h" #include "lib/util_path.h" #include "lib/util_proc.h" +#include "bootmap.h" +#include "disk.h" +#include "envblk.h" +#include "error.h" +#include "misc.h" +#include "zipl_editenv_cli.h" + /* from linux/fs.h */ #define FIBMAP _IO(0x00, 1) @@ -426,52 +429,6 @@ static int set_effective_site_id(char *arg) return set_site_id_common(arg, &eff_site_id); } -static struct util_opt opt_vec[] = { - UTIL_OPT_SECTION("OPTIONS WITHOUT ARGUMENTS"), - { - .option = { "list", no_argument, NULL, 'l'}, - .desc = "print list of zIPL environment variables with their values", - }, - { - .option = { "reset", no_argument, NULL, 'r'}, - .desc = "remove all variables from zIPL environment", - }, - { - .option = { "verbose", no_argument, NULL, 'V'}, - .desc = "provide more information", - }, - UTIL_OPT_SECTION("OPTIONS WITH ARGUMENTS"), - { - .option = { "target", required_argument, NULL, 't'}, - .argument = "DIR", - .desc = "specify directory, where bootmap file is located", - }, - { - .option = { "site", required_argument, NULL, 'S'}, - .argument = "SITE", - .desc = "specify site ID", - }, - { - .option = { "effective-site", required_argument, NULL, 'E'}, - .argument = "SITE", - .desc = "specify effective site ID", - }, - { - .option = { "set", required_argument, NULL, 's'}, - .argument = "NAME=VALUE", - .desc = "assign value VALUE to variable NAME", - }, - { - .option = { "unset", required_argument, NULL, 'u'}, - .argument = "NAME", - .desc = "remove variable NAME from zIPL environment", - }, - UTIL_OPT_SECTION("STANDARD OPTIONS"), - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END, -}; - int main(int argc, char *argv[]) { enum op_id opcode = INVALID_OP_ID; diff --git a/zipl/src/zipl_editenv_cli.h b/zipl/src/zipl_editenv_cli.h new file mode 100644 index 00000000..9b3cba2d --- /dev/null +++ b/zipl/src/zipl_editenv_cli.h @@ -0,0 +1,58 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef ZIPL_EDITENV_CLI_H +#define ZIPL_EDITENV_CLI_H + +#include "lib/util_opt.h" + +static struct util_opt opt_vec[] = { + UTIL_OPT_SECTION("OPTIONS WITHOUT ARGUMENTS"), + { + .option = { "list", no_argument, NULL, 'l'}, + .desc = "print list of zIPL environment variables with their values", + }, + { + .option = { "reset", no_argument, NULL, 'r'}, + .desc = "remove all variables from zIPL environment", + }, + { + .option = { "verbose", no_argument, NULL, 'V'}, + .desc = "provide more information", + }, + UTIL_OPT_SECTION("OPTIONS WITH ARGUMENTS"), + { + .option = { "target", required_argument, NULL, 't'}, + .argument = "DIR", + .desc = "specify directory, where bootmap file is located", + }, + { + .option = { "site", required_argument, NULL, 'S'}, + .argument = "SITE", + .desc = "specify site ID", + }, + { + .option = { "effective-site", required_argument, NULL, 'E'}, + .argument = "SITE", + .desc = "specify effective site ID", + }, + { + .option = { "set", required_argument, NULL, 's'}, + .argument = "NAME=VALUE", + .desc = "assign value VALUE to variable NAME", + }, + { + .option = { "unset", required_argument, NULL, 'u'}, + .argument = "NAME", + .desc = "remove variable NAME from zIPL environment", + }, + UTIL_OPT_SECTION("STANDARD OPTIONS"), + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END, +}; + +#endif